我正在尝试编译此示例程序
#include <iostream>
#include <gmpxx.h>
int main(int argc, const char * argv[])
{
mpz_class rho = 3;
std:cout << rho;
return 0;
}
我收到此错误:
Undefined symbols for architecture x86_64:
"___gmpz_clear", referenced from:
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr() in main-5858d5.o
"___gmpz_init_set_si", referenced from:
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_si(long) in main-5858d5.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我用这个命令手动编译我的主:
clang++ -L /opt/local/lib -I /opt/local/include -lgmpxx main.cpp
GMP已通过MacPorts安装:
$port list gmp
gmp @6.0.0 devel/gmp
编译器的信息:
$clang++ --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
更多信息:
ll /opt/local/lib/libgmp*
/opt/local/lib/libgmp.10.dylib
/opt/local/lib/libgmp.a
/opt/local/lib/libgmp.dylib -> libgmp.10.dylib
/opt/local/lib/libgmpxx.4.dylib
/opt/local/lib/libgmpxx.a
/opt/local/lib/libgmpxx.dylib -> libgmpxx.4.dylib
和
ll /opt/local/include/gmp*
/opt/local/include/gmp.h
/opt/local/include/gmpxx.h
答案 0 :(得分:1)
正在运行clang++ -L /opt/local/lib -I /opt/local/include -lgmpxx -lgmp main.cpp
,感谢@ n.m。