xcode 在 Mac 上,默认情况下 g++ (clang) 无法搜索 /usr/local/include 和 /usr/local/lib
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23905661/
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
On mac, g++ (clang) fails to search /usr/local/include and /usr/local/lib by default
提问by math4tots
I'm on a mac and I used homebrew
to install gmp
.
我在 mac 上,我曾经homebrew
安装gmp
.
Kyumins-iMac:gcjlib math4tots$ g++ main.cpp -lgmp -lgmpxx
In file included from main.cpp:2:
./gcjlib.hpp:4:10: fatal error: 'gmpxx.h' file not found
#include <gmpxx.h>
^
1 error generated.
So then I explicitly told g++
to use /usr/local/include
然后我明确告诉g++
使用/usr/local/include
Kyumins-iMac:gcjlib math4tots$ g++ main.cpp -lgmp -lgmpxx -I/usr/local/include
ld: library not found for -lgmp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So then I explicitly told g++
to use /usr/local/lib
然后我明确告诉g++
使用/usr/local/lib
Kyumins-iMac:gcjlib math4tots$ g++ main.cpp -lgmp -lgmpxx -I/usr/local/include -L/usr/local/lib
Kyumins-iMac:gcjlib math4tots$ ./a.out
sum is -4444
absolute value is 4444
So the only issue seems to be that g++
fails to acknowledge /usr/local
.
所以唯一的问题似乎是g++
不承认/usr/local
。
But it is tedious to type all this out all the time, especially when I'm just writing small single file programs.
但是一直把所有这些都打出来是很乏味的,尤其是当我只是在编写小的单文件程序时。
Is there a way for me to get g++
to acknowledge the stuff in /usr/local
by default? Is there a standard way homebrew
users do this?
有没有办法让我g++
在/usr/local
默认情况下承认这些东西?homebrew
用户是否有标准的方式来做到这一点?
I'm on OS X 10.9.3 with Xcode 5.1.1 in case it is relevant.
我在 OS X 10.9.3 上使用 Xcode 5.1.1,以防万一。
回答by Jonas Sellberg
I also use Homebrew and had a similar problem on Mac OSX Maverick 10.9.5 and Xcode 6.0.1, but it was solved by running:
我也使用 Homebrew 并在 Mac OSX Maverick 10.9.5 和 Xcode 6.0.1 上遇到了类似的问题,但通过运行解决了:
xcode-select --install
xcode-select --install
Note that it doesn't work without the double hyphens given by the previous answer. This installs the command-line tools that also create /usr/lib/
and /usr/include/
. I don't know why Homebrew doesn't automatically check this upon installation, since it does check for Xcode...
请注意,如果没有上一个答案给出的双连字符,它就不起作用。这会安装命令行工具,这些工具还可以创建/usr/lib/
和/usr/include/
. 我不知道为什么 Homebrew 在安装时不会自动检查这个,因为它会检查 Xcode ......
If you want to check exactly what folders your compiler is looking through for header files you can write:
如果您想确切地检查您的编译器正在查找头文件的文件夹,您可以编写:
cpp -v
cpp -v
回答by Philippe
A workaround would be to:
一种解决方法是:
export C_INCLUDE_PATH=/usr/local/include
export CPLUS_INCLUDE_PATH=/usr/local/include
At least this tricked the pre-processor to behave here :)
至少这欺骗了预处理器在这里表现:)
回答by Russell Owen
Try running xcode-select --install
尝试跑步 xcode-select --install
At least on Mavericks, I've found that if I install the Xcode application without installing the command-line tools, then the tools are sort of available, but normal unix-ey builds don't work correctly. One symptom is that /usr/local/include
is not on the include search path. The command-line tools seem to resolve this issue.
至少在 Mavericks 上,我发现如果我在没有安装命令行工具的情况下安装 Xcode 应用程序,那么这些工具是可用的,但是正常的 unix-ey 构建不能正常工作。一种症状是/usr/local/include
不在包含搜索路径上。命令行工具似乎解决了这个问题。
回答by mchan
I have Yosemite 10.10.5 and running xcode-select --install
didn't fix the problem for me. The command returned with xcode-select: error: command line tools are already installed, use "Software Update" to install updates
.
我有 Yosemite 10.10.5 并且运行xcode-select --install
并没有解决我的问题。命令返回xcode-select: error: command line tools are already installed, use "Software Update" to install updates
。
When I ran xcode-select -p
, it showed /Applications/Xcode.app/Contents/Developer
. I ended up deleting Xcode from the Applications directory, which resulted in xcode-select -p
returning /Library/Developer/CommandLineTools
. This fixed compiler error for me.
当我跑的时候xcode-select -p
,它显示了/Applications/Xcode.app/Contents/Developer
。我最终从 Applications 目录中删除了 Xcode,这导致xcode-select -p
返回/Library/Developer/CommandLineTools
. 这对我来说是固定的编译器错误。
回答by Vyacheslav
That was helpful for me:
这对我很有帮助:
Use the latest version. 1.0.2o_1
just a current build.
使用最新版本。1.0.2o_1
只是当前版本。
brew install openssl
ln -s /usr/local/Cellar/openssl/1.0.2o_1/include/openssl /usr/local/include/openssl
ln -s /usr/local/Cellar/openssl/1.0.2o_1/lib /usr/local/lib/openssl