C++ 如何使用macports中安装的gcc?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8361002/
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
How to use the gcc installed in macports?
提问by Nemo
I installed gcc 4.6. from macports (for support of C++0x). But when I check the 'gcc --version` it is showing older version. How to use the newer gcc installed by macports?
我安装了 gcc 4.6。来自 macports(用于支持 C++0x)。但是当我检查“gcc --version”时,它显示的是旧版本。如何使用 macports 安装的较新的 gcc?
采纳答案by Nikolai Fetissov
I remember it being something like g++-mp-4.6. I believe it's enough to set the environment variable CXXto that.
我记得它是类似的东西g++-mp-4.6。我相信将环境变量设置为该环境变量CXX就足够了。
回答by raimue
You can control the symlink in /opt/local/bin/gccby using port select. You can see available version using port select --list gcc. Anything listed with mp- as prefix refers to MacPorts' own port, gcc42 and llvm-gcc42 refer to the compilers shipped with Xcode by Apple.
您可以/opt/local/bin/gcc使用来控制符号链接port select。您可以使用port select --list gcc. 任何以 mp- 作为前缀的内容都是指 MacPorts 自己的端口,gcc42 和 llvm-gcc42 是指 Apple 随 Xcode 一起提供的编译器。
Example from my system:
我的系统中的示例:
$ port select --list gcc
Available versions for gcc:
gcc42
llvm-gcc42
mp-gcc45
none (active)
$ sudo port select --set gcc mp-gcc45
Password:
Selecting 'mp-gcc45' for 'gcc' succeeded. 'mp-gcc45' is now active.
After that, either open a new terminal window or issue hash -rto make bash recognize the change.
之后,打开一个新的终端窗口或发出问题hash -r让 bash 识别更改。
回答by Michael Krelin - hacker
Just make sure macports' path comes first in your $PATH. Or use gcc-mp-4.6or something like that.
只需确保 macports 的路径在您的$PATH. 或使用gcc-mp-4.6或类似的东西。

