gpt4 book ai didi

c++ - GMP 库 6.0.0 无法在 Mac OS Mavericks 上编译

转载 作者:行者123 更新时间:2023-11-28 06:42:39 27 4
gpt4 key购买 nike

我正在尝试编译这个示例程序

#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)

我用这个命令手动编译我的 main:

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

最佳答案

运行 clang++ -L/opt/local/lib -I/opt/local/include -lgmpxx -lgmp main.cpp 成功了,谢谢@n.m。

关于c++ - GMP 库 6.0.0 无法在 Mac OS Mavericks 上编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25671605/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com