Setting Environment Variable For XCode

From WxWiki
Jump to: navigation, search

You can define an environment variable such as WXWIN to point to the location of your wx directory. This enables to use (WXWIN)/include instead of /wxWidgets/wx262/include for paths in your project settings. If you upgrade or use more than one version of wxWidgets, all you need to change is one environment variable instead of many project settings.

Before you start:

  • Each user's environment variables are included in a file called <tt>environment.plist</tt>
  • The file resides in the directory ~/.MacOSX/ which must be created from the terminal or via the Property List Editor.

How to create an environment variable:

Method 1: Using Property List Editor

  • Open the ''Property List Editor'' (/Developer/Applications/Utilities)
  • Click on ''New Root''
  • Select the new root and click on ''New Child'', name it <tt>WXWIN</tt>
  • Double-click on the value area on the right and enter the location of your wx root folder (eg, /wxWidgets/wx261
  • Click on ''Dump''
  • Save it under your user folder (~/) with the name environment.plist (small case)
  • Open a terminal window and execute:
  • cd ~
  • md .MacOSX
  • cd .MacOSX
  • cp ../environment.plist environment.plist

Method 2: Using Terminal

The defaults command-line tool allows insertion of key/value pairs into plists, and this is the simplest means of adding an environment variable. The commands defaults write ~/.MacOSX/environment WXWIN -string "/wxWidgets/wx261"; plutil -convert xml1 ~/.MacOSX/environment.plist will insert the variable, creating the plist file if necessary. The second part of the command keeps the plist in text format, instead of the default binary format.

  • You will have to log out for changes to take effect


For more information see Apple's QA1067

XCode 3.0 issue

There is currently an issue in XCode 3.0 where environment variables in the environment.plist are not read when XCode is launched from Spotlight. The workaround is to launch XCode from the dock or the finder.

For more information see this Apple forum note.