我使用 homebrew
在我的 Mac 上安装了 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,如果相关的话。
g++ --version
命令来查看你正在运行的版本。 - Richard