[英]How do I make sure that my default C/C++ compiler is GCC
I'm trying to install Riak from source on macOS ( https://docs.riak.com/riak/kv/2.2.3/setup/installing/mac-osx.1.html#installing-from-source ).我正在尝试在 macOS 上从源代码安装 Riak( https://docs.riak.com/riak/kv/2.2.3/setup/installing/mac-osx.1.html#installing-from-source )。
There is a note:有一个注释:
Riak will not compile with Clang.
Riak 不会与 Clang 一起编译。 Please make sure that your default C/C++ compiler is GCC
请确保您的默认 C/C++ 编译器是 GCC
How do I find out which compiler is the default and how to change it?如何找出默认的编译器以及如何更改它?
macOS Catalina (10.15.4), which command prints: macOS Catalina (10.15.4),该命令打印:
$ which clang
/usr/bin/clang
$ which gcc
/usr/bin/gcc
On macOS Catalina (and prior versions, and most likely subsequent versions too), there are two aspects to the problem and some suggested solutions.在 macOS Catalina(以及之前的版本,很可能还有后续版本)上,问题有两个方面和一些建议的解决方案。
make
by default? make
默认使用的编译器名称是什么?$ mkdir junk
$ cd junk
$ > x.cpp
$ > y.c
$ make x y
c++ x.cpp -o x
cc y.c -o y
$ cd ..
$ rm -fr junk
This shows that the names used by make
are cc
and c++
.这表明
make
使用的名称是cc
和c++
。 Those are not obviously clang
or clang++
, but neither are they obviously gcc
and g++
.这些显然不是
clang
或clang++
,但也不是显然gcc
和g++
。
$ which cc c++
/usr/bin/cc
/usr/bin/c++
$
Which compiler really lives behind the names cc
, c++
, gcc
, g++
, clang
, and clang++
?哪个编译器真正存在于名称后面
cc
, c++
, gcc
, g++
, clang
和clang++
754 FFZ 和 AE? We can check which compiler these really are by getting them to identify their version:我们可以通过让它们识别它们的版本来检查它们到底是哪个编译器:
$ for compiler in cc c++ gcc g++ clang clang++
> do
> which $compiler
> $compiler --version
> done
/usr/bin/cc
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
/usr/bin/c++
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
/usr/bin/gcc
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
/usr/bin/g++
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
/usr/bin/clang
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
/usr/bin/clang++
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$
As you can see, the versions installed in /usr/bin
are all the same compiler, and that compiler is clang
or clang++
.可以看到,
/usr/bin
中安装的版本都是同一个编译器,编译器是clang
或clang++
。
This was run on a machine with macOS Mojave 10.14.6 and XCode 11.3.1.这是在装有 macOS Mojave 10.14.6 和 XCode 11.3.1 的机器上运行的。 The latest version of XCode — 11.4.1 — is only available on Catalina.
最新版本的 XCode — 11.4.1 — 仅在 Catalina 上可用。 However, the general conclusion is the same — all the C and C++ compilers are really
clang
and clang++
in disguise.但是,一般结论是相同的——所有的 C 和 C++ 编译器实际上都是伪装的
clang
和clang++
。
How do you get a real GNU GCC — a real GCC, not clang
in disguise — onto your machine?你如何得到一个真正的 GNU GCC——一个真正的 GCC,而不是
clang
伪装到你的机器上?
Be aware that Apple has taken to hiding the system header files miles out of the way (not in /usr/include
— and you can't modify that part of the file system to add a symlink to where they've hidden them):请注意,Apple 已采取隐藏系统 header 文件的方式(不在
/usr/include
中 - 您无法修改文件系统的该部分以添加符号链接到他们隐藏它们的位置):
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
(You mean you couldn't guess that? Me neither!) (你的意思是你猜不到?我也猜不到!)
Once you have GCC installed somewhere appropriate, you need to ensure you use the 'real' GCC and not the 'fake' in /usr/bin
.一旦你在适当的地方安装了 GCC ,你需要确保你使用“真实的” GCC 而不是
/usr/bin
中的“假”。 You do that in part by ensuring that the bin directory for the 'real' GCC occurs on your PATH before /usr/bin
.您可以通过确保“真实” GCC 的 bin 目录出现在
/usr/bin
之前的路径上来部分地做到这一点。 I have GCC 9.3.0 installed under /opt/gcc/v9.3.0
, so /opt/gcc/v9.3.0/bin
appears on my PATH long before /usr/bin
does.我在 /opt/gcc/v9.3.0 下安装了
/opt/gcc/v9.3.0
,所以/opt/gcc/v9.3.0/bin
早在/usr/bin
出现在我的 PATH 上。
You also need to ensure that the configuration for riak
(the software you're installing) uses the correct compilers.您还需要确保
riak
(您正在安装的软件)的配置使用正确的编译器。 If there's a ./configure
script, run it with the correct path specified for the compilers.如果有
./configure
脚本,请使用为编译器指定的正确路径运行它。 For example, I might use:例如,我可能会使用:
./configure CC=/opt/gcc/v9.3.0/bin/gcc CXX=/opt/gcc/v9.3.0/bin/g++
You can also set these values as environment variables.您还可以将这些值设置为环境变量。
If it uses cmake
or some other configuration package, you'll need to consult the installation instructions.如果它使用
cmake
或其他一些配置 package,则需要查阅安装说明。 That's usually README
or sometimes INSTALL
.这通常是
README
或有时是INSTALL
。
See also (increasingly older posts):另见(越来越老的帖子):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.