在 mac 上,默认情况下 g++ (clang) 无法搜索/usr/local/include 和/usr/local/lib [英] On mac, g++ (clang) fails to search /usr/local/include and /usr/local/lib by default

查看:39
本文介绍了在 mac 上,默认情况下 g++ (clang) 无法搜索/usr/local/include 和/usr/local/lib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 mac,我使用 homebrew 来安装 gmp.

I'm on a mac and I used homebrew to install 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.

然后我明确告诉 g++ 使用 /usr/local/include

So then I explicitly told g++ to use /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)

然后我明确告诉 g++ 使用 /usr/local/lib

So then I explicitly told g++ to use /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

所以唯一的问题似乎是 g++ 未能确认 /usr/local.

So the only issue seems to be that g++ fails to acknowledge /usr/local.

但是一直把所有这些都打出来很乏味,尤其是当我只是在编写小型的单文件程序时.

But it is tedious to type all this out all the time, especially when I'm just writing small single file programs.

有没有办法让 g++ 默认确认 /usr/local 中的内容?homebrew 用户是否有标准的方法来执行此操作?

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?

我使用的是 OS X 10.9.3 和 Xcode 5.1.1,以防万一.

I'm on OS X 10.9.3 with Xcode 5.1.1 in case it is relevant.

推荐答案

我也使用 Homebrew,在 Mac OSX Maverick 10.9.5 和 Xcode 6.0.1 上也遇到过类似问题,但是通过运行解决了:

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:

xcode-select --install

请注意,如果没有上一个答案给出的双连字符,它就不起作用.这将安装还创建 /usr/lib//usr/include/ 的命令行工具.我不知道为什么 Homebrew 在安装时不会自动检查这个,因为它会检查 Xcode...

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...

如果你想准确地检查你的编译器在哪些文件夹中查找头文件,你可以这样写:

If you want to check exactly what folders your compiler is looking through for header files you can write:

cpp -v

这篇关于在 mac 上,默认情况下 g++ (clang) 无法搜索/usr/local/include 和/usr/local/lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆