在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

查看:2313
本文介绍了在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

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?

推荐答案

我也使用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天全站免登陆