【发布时间】:2014-07-17 07:47:59
【问题描述】:
我在 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.
然后我明确告诉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
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。
但是一直把这些都打出来很乏味,尤其是当我只是写小的单文件程序时。
有没有办法让g++ 默认承认/usr/local 中的内容? homebrew 用户是否有标准的方式来执行此操作?
我使用的是 OS X 10.9.3 和 Xcode 5.1.1,以防万一。
【问题讨论】:
-
使用makefile怎么样?
-
请不要再说
g++,您正在调用的程序是clang++(通过苹果提供的令人困惑的别名),您的问题与gcc无关。如果您确实安装了真正的 gcc,它可能会按预期工作。 -
$ sudo rm -rf Applications/Xcode.app在 10.12.6 为我工作。 -
您可以使用
g++ --version查看您实际运行的内容。