Share via


Using Environment Variables

Environment variables are the variables set by the operating system; they allow for specifying a directory to find project files or copy output files. How environment variables are set differs between Windows 95 and Windows NT.

Environment variables are used in the Project Settings dialog box, especially on these tabs : Custom Build Rules, C/C++, Link, and Resources.

To set environment variables with Windows NT

  1. On the Start menu, point to Settings, then click Control Panel.

  2. In the Control Panel, double click System.

  3. In the System Properties dialog box, click the Environment tab, and specify your environment variable setting, using the User Variables for, Variable, and Value boxes.

  4. Exit the development environment and restart it for the changed environment variable to take effect.

To set environment variables with Windows 95

  1. Add the environment variable to the autoexec.bat file.

  2. Restart Windows 95 for the change to take effect.

     

Example

Following is an example of using environment variables in a multi-user situation.

Take the project “BldSys.exe,” which uses a library called Mylib.lib. Each user places the Mylib library and include files in a different directory or drive.

To solve this problem, define the environment variable MYLIB.

User 1 sets MYLIB to:

MYLIB = c:\mylib

User 2 sets MYLIB to:

MYLIB = d:\dev\mylib

In the Project Settings dialog box (Project menu), click the C/C++ tab, then click Preprocessor in the Categories list. In the Additional include directories box, type $(MYLIB)\include.

On User 1’s machine, this setting resolves to:

C:\mylib\include

On User 2’s machine, this setting resolves to:

D:\dev\mylib\include

Warning   Although the Project Settings dialog box supports environment variables, it is not recommended that environment variables be used except in the Additional include directories box, and in the way suggested. Do not use environment variables to throw switches that change the name or location of output files.

Environment variables are also useful for custom build rules. For example, you can copy output files to a binary directory that could be in any arbitrary location on the user’s machine.

For example, suppose you have a setting you want to specify such as BIN=C:\binnt In the Project Settings dialog box, click the Custom Build tab, then click the first available line in the Build Commands box and type the following:

copy $(TargetName)$(BIN)$(TargetName)

Then, in the Output Files box, add:

$(BIN)$(TargetName)