OS X选择llvm gcc编译器

时间:2022-04-08 07:00:38

TLDR: I want to use the llvm compiler, not some other gcc compiler that I installed using macports.

TLDR:我想使用llvm编译器,而不是使用macports安装的其他gcc编译器。

Whilst trying to compile a c++ library, I ran into this error:

在尝试编译c ++库时,我遇到了这个错误:

c++: error: unrecognized option '-arch'

After searching on SO, I found this post post which indicates that the '-arch' option is part of Apple's extensions to gcc.

在SO上搜索之后,我发现这篇文章帖子表明'-arch'选项是Apple对gcc扩展的一部分。

A while ago I installed a different GCC version, using Macports, in order to compile some tools for some other software. Now when I check this, I can confirm that it is using the version from Macports:

不久之前,我使用Macports安装了一个不同的GCC版本,以便为其他软件编译一些工具。现在当我检查这个时,我可以确认它正在使用Macports的版本:

$ g++ --version
g++ (MacPorts gcc46 4.6.4_3) 4.6.4
$ which g++ --version
/opt/local/bin/g++

Using port select only yields two options,

使用端口选择只产生两个选项,

$ port select --list gcc
Available versions for gcc:
    mp-gcc46 (active)
    none

So I can't change the default compiler here. Where can I change this to use the llvm compiler in /usr/bin/?

所以我不能在这里更改默认编译器。我在哪里可以更改此项以在/ usr / bin /中使用llvm编译器?

3 个解决方案

#1


2  

The compiler that comes with LLVM is Clang, not GCC. Have you got XCode 5 installed? And the command line tools as well? This post explains how to install them quite clearly.

LLVM附带的编译器是Clang,而不是GCC。你安装了XCode 5吗?和命令行工具一样?这篇文章解释了如何非常清楚地安装它们。

Then you can try to run clang --version to verify that clang has been installed properly and is available in the command line. Then to compile with auto-tools, you can pass it in the CC and CXX variables as @paul-roub said:

然后,您可以尝试运行clang --version来验证clang是否已正确安装并且在命令行中可用。然后使用自动工具进行编译,你可以在CC和CXX变量中传递它,因为@ paul-roub说:

CC=clang CXX=clang++ ./configure
make

Bear in mind that Apple is using a modified version of LLVM/Clang. They used to use GCC before but they dropped the support for it when the license changed to GPLv3 if I remember correctly. On a clean 10.9 install with XCode 5.1 you shouldn't have GCC at all though, it's been completely replaced by Clang.

请记住,Apple正在使用LLVM / Clang的修改版本。他们过去常常使用GCC,但如果我没记错,他们会在许可证更改为GPLv3时放弃对它的支持。在使用XCode 5.1进行干净的10.9安装时,您根本不应该使用GCC,它已被Clang完全取代。

#2


1  

Configure scripts and Makefiles will often respect the CC and CXX environment variables, telling them to use a specific compiler.

配置脚本和Makefile通常会尊重CC和CXX环境变​​量,告诉他们使用特定的编译器。

e.g.:

$ CXX=/usr/bin/g++ CC=/usr/bin/gcc ./configure
$ CXX=/usr/bin/g++ CC=/usr/bin/gcc make

#3


1  

I believe you need to select none to go back to the default compiler. If no gcc compiler is selected using macports (and therefore, no link called gcc exists in /opt/bin) then the first gcc compiler encountered will be the one in /usr/bin.

我相信您需要选择none才能返回默认编译器。如果没有使用macports选择gcc编译器(因此,/ opt / bin中不存在名为gcc的链接),那么遇到的第一个gcc编译器将是/ usr / bin中的编译器。

#1


2  

The compiler that comes with LLVM is Clang, not GCC. Have you got XCode 5 installed? And the command line tools as well? This post explains how to install them quite clearly.

LLVM附带的编译器是Clang,而不是GCC。你安装了XCode 5吗?和命令行工具一样?这篇文章解释了如何非常清楚地安装它们。

Then you can try to run clang --version to verify that clang has been installed properly and is available in the command line. Then to compile with auto-tools, you can pass it in the CC and CXX variables as @paul-roub said:

然后,您可以尝试运行clang --version来验证clang是否已正确安装并且在命令行中可用。然后使用自动工具进行编译,你可以在CC和CXX变量中传递它,因为@ paul-roub说:

CC=clang CXX=clang++ ./configure
make

Bear in mind that Apple is using a modified version of LLVM/Clang. They used to use GCC before but they dropped the support for it when the license changed to GPLv3 if I remember correctly. On a clean 10.9 install with XCode 5.1 you shouldn't have GCC at all though, it's been completely replaced by Clang.

请记住,Apple正在使用LLVM / Clang的修改版本。他们过去常常使用GCC,但如果我没记错,他们会在许可证更改为GPLv3时放弃对它的支持。在使用XCode 5.1进行干净的10.9安装时,您根本不应该使用GCC,它已被Clang完全取代。

#2


1  

Configure scripts and Makefiles will often respect the CC and CXX environment variables, telling them to use a specific compiler.

配置脚本和Makefile通常会尊重CC和CXX环境变​​量,告诉他们使用特定的编译器。

e.g.:

$ CXX=/usr/bin/g++ CC=/usr/bin/gcc ./configure
$ CXX=/usr/bin/g++ CC=/usr/bin/gcc make

#3


1  

I believe you need to select none to go back to the default compiler. If no gcc compiler is selected using macports (and therefore, no link called gcc exists in /opt/bin) then the first gcc compiler encountered will be the one in /usr/bin.

我相信您需要选择none才能返回默认编译器。如果没有使用macports选择gcc编译器(因此,/ opt / bin中不存在名为gcc的链接),那么遇到的第一个gcc编译器将是/ usr / bin中的编译器。