xcode 将 GCC 4.2 设置为 Mac OS X Leopard 上的默认编译器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1165361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting GCC 4.2 as the default compiler on Mac OS X Leopard
提问by Cromulent
I'm sure there must be a way to do this. As you are probably aware the latest versions of Xcode (and in fact I think all versions of Xcode) on Leopard come with GCC 4.0.1 and GCC 4.2. GCC 4.0.1 is the default system compiler while GCC 4.2 is an optional compiler you can set in the Xcode project settings.
我相信一定有办法做到这一点。正如您可能知道 Leopard 上最新版本的 Xcode(实际上我认为 Xcode 的所有版本)都带有 GCC 4.0.1 和 GCC 4.2。GCC 4.0.1 是默认的系统编译器,而 GCC 4.2 是一个可选的编译器,您可以在 Xcode 项目设置中进行设置。
Does anyone know how to set GCC 4.2 as the default compiler for all options? Preferably command line use as well as configure scripts still use GCC 4.0.1 rather than GCC 4.2 no matter what I do in Xcode. I'm assuming it is simply a case of changing a path variable or some such but I am stumped on this one.
有谁知道如何将 GCC 4.2 设置为所有选项的默认编译器?无论我在 Xcode 中做什么,命令行使用和配置脚本仍然使用 GCC 4.0.1 而不是 GCC 4.2。我假设这只是更改路径变量或其他变量的一种情况,但我对此感到困惑。
Any help is appreciated. Thanks.
任何帮助表示赞赏。谢谢。
采纳答案by Martin v. L?wis
Command line usage for all configure scripts:
所有配置脚本的命令行用法:
cd /usr/bin
rm cc gcc c++ g++
ln -s gcc-4.2 cc
ln -s gcc-4.2 gcc
ln -s c++-4.2 c++
ln -s g++-4.2 g++
Make a record of the current link targets, so you can restore them if you want to.
记录当前链接目标,以便您可以根据需要恢复它们。
If you don't want to change the system wide settings, add a directory into PATH before /usr/bin (say, $HOME/bin
), and make the symlinks there
如果您不想更改系统范围的设置,请在 /usr/bin 之前将目录添加到 PATH(例如,$HOME/bin
),并在那里制作符号链接
I haven't tested whether this affects Xcode projects, since I don't use Xcode (only command line).
我没有测试这是否会影响 Xcode 项目,因为我不使用 Xcode(仅命令行)。
回答by IlDan
In the Project or Target Info Window set the build setting "C/C++ compiler version" (GCC_VERSION).
在项目或目标信息窗口中设置构建设置“C/C++ 编译器版本”(GCC_VERSION)。
Or in the Target Info Window you can change the "System C rule" to your favorite GCC version.
或者在目标信息窗口中,您可以将“系统 C 规则”更改为您喜欢的 GCC 版本。
Update: Regarding the command line I would leave to Leopard the decision of what should be the default compiler. If you want to use a different compiler with tools like Autotools configure you had better to define the CC variable.
更新:关于命令行,我会让 Leopard 决定什么应该是默认编译器。如果您想将不同的编译器与 Autotools configure 之类的工具一起使用,您最好定义 CC 变量。
CC=gcc-4.2 ./configure
or
或者
export CC=gcc-4.2
回答by user156592
Since neitherApple nor Darwin Ports have the gcc_select program to change the default version of the System compiler(as exists on GNU/Linux), I would like to be on the safe side with XCode (and the rest of the system) and would recommend to leave the symbolic links as they are and instead setup environment variables that overrides which version of GCC to use.
由于既没有苹果也不是达尔文港口有gcc_select程序更改的默认版本系统的编译器(在GNU / Linux的存在),我想是在安全方面具有的XCode(和系统的其余部分),并建议保留符号链接原样,而是设置覆盖要使用的 GCC 版本的环境变量。
In my .profile file I have the following
在我的 .profile 文件中,我有以下内容
export CC=/usr/bin/gcc-4.2
export CPP=/usr/bin/cpp-4.2
export CXX=/usr/bin/g++-4.2
And I successfully compiled the following libraries with GCC 4.2 from source.
我从源代码成功地使用 GCC 4.2 编译了以下库。
- OpenSSL
- libjpeg
- libpng
- zlib
- gst
- 开放式SSL
- libjpeg
- 压缩包
- zlib
- 消费税
However... I could not get Boost 1.39 to acknowledge the environment variables, so to compile Boost with GCC 4.2 I needed to change the symbolic links in /usr/bin/ so they pointed to gcc v4.2
但是......我无法让 Boost 1.39 来确认环境变量,所以要使用 GCC 4.2 编译 Boost,我需要更改 /usr/bin/ 中的符号链接,因此它们指向 gcc v4.2
After the long while the Boost libraries were finished compiling with GCC 4.2 I restored the symbolic links back to the original System version gcc-4.0.
在使用 GCC 4.2 完成 Boost 库的编译很久之后,我将符号链接恢复到原始系统版本 gcc-4.0。
回答by Centzon
Im my experience (limited), changing CC in .profile does not change Lion's (10.7.2) defaulting to i686-apple-darwin11-llvm-gcc-4.2. I wonder if this has anything to do with Apple's own sym linking:
a partial: ls -la /usr/bin | grep .*gcc.*
:
我的经验(有限),更改 .profile 中的 CC 不会更改 Lion 的(10.7.2)默认为 i686-apple-darwin11-llvm-gcc-4.2。我想知道这是否与 Apple 自己的符号链接有关:部分ls -la /usr/bin | grep .*gcc.*
::
lrwxr-xr-x 1 root wheel 12 25 oct 19:31 cc -> llvm-gcc-4.2
lrwxr-xr-x 1 root wheel 12 25 oct 19:31 gcc -> llvm-gcc-4.2
lrwxr-xr-x 1 root admin 32 25 oct 19:31 llvm-gcc-4.2 -> ../llvm-gcc-4.2/bin/llvm-gcc-4.2
I am wary about breaking these and adding my own to usr/bin/gcc-4.2 per Martin v. L?wis's answer.
根据 Martin v. L?wis 的回答,我很担心打破这些并将我自己的添加到 usr/bin/gcc-4.2 中。
回答by Centzon
I might be wrong, but I thought that was what Xcode-select was for?
我可能错了,但我认为这就是 Xcode-select 的用途?
xcode-select --switch /path_to_tool_suite
As I said, I'm not 100% on this, but I believe it will set the default for all programs including Terminal and other apps that calls into the OS to use a compiler.
正如我所说,我不是 100% 对此,但我相信它将为所有程序设置默认值,包括终端和其他调用操作系统以使用编译器的应用程序。
回答by Stephan Deibel
Since I need to build things where CC env is ignored and I end up switching often, I wrote a simple minded gcc_select in Python. Thought I may as well post it here. Invoke it with arg either 4.0 or 4.2 or no arg to see current symlinks. Would need modification if you have versions other than 4.0 and 4.2:
由于我需要构建一些忽略 CC env 并且最终经常切换的东西,我用 Python 编写了一个头脑简单的 gcc_select 。我想我也可以把它贴在这里。使用 arg 4.0 或 4.2 或无 arg 调用它以查看当前符号链接。如果您有 4.0 和 4.2 以外的版本,则需要修改:
#!/usr/bin/python
import sys
import os
os.chdir('/usr/bin')
files = ['cc', 'gcc', 'c++', 'g++']
if '4.0' in sys.argv:
ver = '4.0'
elif '4.2' in sys.argv:
ver = '4.2'
else:
print "Unknown gcc version. Current setting:"
os.system('ls -al %s' % ' '.join(files))
sys.exit(1)
os.system('rm %s' % ' '.join(files))
for f in files:
os.system('ln -s %s-%s %s' % (f, ver, f))
print "Changed to gcc version %s" % ver