Change default g++ architecture on Mac OS X?
With Mac OS X 10.6 Apple changed the default target of g++ so it produces 64-bit rather than 32-bit code. I know I can specify "-arch i386" on the command line but is there any way to globally change the default architecture by means of an environment variable or similar? (I keep getting linking errors becau开发者_JS百科se I'm having real problems finding all the places I need to specify the architecture on the project I'm porting.)
Not that I know of. Depending on the configuration & build system you’re using, setting the CXXFLAGS
, CFLAGS
, and LDFLAGS
environmental variables to include -arch i386
can help. However, some configuration & build system are tricky and it might not be sufficient to set those variables.
Another option is to provide a g++
(and friends as needed) bash script in a PATH
location that precedes /usr/bin
and invokes the actual command with -arch i386
along with the command-line arguments passed to the script.
An alternative to the solution described in the previous paragraph is to use arch(1)
in one of its various forms. For instance, the shell script described above could invoke arch -i386 /usr/bin/g++
. You can also set the ARCHPREFERENCE
environmental variable to something like g++:/usr/bin/g++:i386,x86_64
and invoke arch /usr/bin/g++
. However, note that you must use arch
to invoke /usr/bin/g++
.
Option 1
You could set your path so that it searches your private bin directory first.
In this bin directory place a g++ script that explicitly invokes the correct g++ compiler will the appropriate flags.
Option 2
Set a g++ alias. This will then be used in preference to a command. Set the alias to run the command with the appropriate flags.
Note: Both of these assume you are building from the command line as XCode probably explicitly executes the g++ binary.
精彩评论