得到了一个未定义的符号'使用GINAC编译.CPP文件时出错
我使用gcc(版本11)编译我的.cpp
文件,代码如下,是从ginac官网复制的。
#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
int main()
{
symbol x("x"), y("y");
ex poly;
for (int i=0; i<3; ++i)
poly += factorial(i+16)*pow(x,i)*pow(y,2-i);
cout << poly << endl;
return 0;
}
我使用了这样的编译命令:
gcc-11 -lstdc++ -lginac -lcln hello.cpp -o hello -I /usr/local/include -L /usr/local/lib
之后,我得到了一些这样的错误:
Undefined symbols for architecture x86_64:
"__ZN5GiNaC12archive_node6add_exERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_2exE", referenced from:
__ZNK5GiNaC9containerISt6vectorE7archiveERNS_12archive_nodeE in ccEkVJyo.o
"__ZN5GiNaC5basic12read_archiveERKNS_12archive_nodeERNS_9containerINSt7__cxx114listEEE", referenced from:
__ZN5GiNaC9containerISt6vectorE12read_archiveERKNS_12archive_nodeERNS0_INSt7__cxx114listEEE in ccEkVJyo.o
"__ZN5GiNaC6symbolC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
_main in ccEkVJyo.o
"__ZN5GiNaC9containerISt6vectorE8reg_infoE", referenced from:
__ZN5GiNaC9containerISt6vectorE21get_class_info_staticEv in ccEkVJyo.o
"__ZN5GiNaClsERSoRKNS_2exE", referenced from:
_main in ccEkVJyo.o
"__ZNK5GiNaC12archive_node14find_ex_by_locEN9__gnu_cxx17__normal_iteratorIPKNS0_8propertyESt6vectorIS3_SaIS3_EEEERNS_2exERNS_9containerINSt7__cxx114listEEE", referenced from:
__ZN5GiNaC9containerISt6vectorE12read_archiveERKNS_12archive_nodeERNS0_INSt7__cxx114listEEE in ccEkVJyo.o
"__ZNK5GiNaC12archive_node19find_property_rangeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_", referenced from:
__ZN5GiNaC9containerISt6vectorE12read_archiveERKNS_12archive_nodeERNS0_INSt7__cxx114listEEE in ccEkVJyo.o
"__ZNK5GiNaC5basic10eval_ncmulERKSt6vectorINS_2exESaIS2_EE", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC5basic11to_rationalERSt3mapINS_2exES2_NS_10ex_is_lessESaISt4pairIKS2_S2_EEE", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC5basic13contract_withEN9__gnu_cxx17__normal_iteratorIPNS_2exESt6vectorIS3_SaIS3_EEEES8_RS7_", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC5basic13to_polynomialERSt3mapINS_2exES2_NS_10ex_is_lessESaISt4pairIKS2_S2_EEE", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC5basic14subs_one_levelERKSt3mapINS_2exES2_NS_10ex_is_lessESaISt4pairIKS2_S2_EEEj", referenced from:
__ZNK5GiNaC9containerISt6vectorE4subsERKSt3mapINS_2exES4_NS_10ex_is_lessESaISt4pairIKS4_S4_EEEj in ccEkVJyo.o
"__ZNK5GiNaC5basic5matchERKNS_2exERSt3mapIS1_S1_NS_10ex_is_lessESaISt4pairIS2_S1_EEE", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC5basic6normalERSt3mapINS_2exES2_NS_10ex_is_lessESaISt4pairIKS2_S2_EEES9_RNS_9containerINSt7__cxx114listEEE", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC9containerISt6vectorE4infoEj", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
我知道由于链接错误经常出现 Undefined Symbols
错误,但是详细的错误消息看起来像这些错误来自 ginac 本身。
我尝试了这些 -l
参数的不同顺序,但错误始终存在。
我尝试用 clang
而不是 gcc
来编译这个文件,它可以工作。所以我想我确实正确安装了 ginac 库。但在使用 gcc
时我仍然对这些错误感到困惑。
有人遇到过这个问题吗?
如果有人能给我一些建议,我将不胜感激!
I'm using gcc(version 11) to compile my .cpp
file, and the code is below, which is copied from the official website of ginac.
#include <iostream>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
int main()
{
symbol x("x"), y("y");
ex poly;
for (int i=0; i<3; ++i)
poly += factorial(i+16)*pow(x,i)*pow(y,2-i);
cout << poly << endl;
return 0;
}
I used the compiling command like this:
gcc-11 -lstdc++ -lginac -lcln hello.cpp -o hello -I /usr/local/include -L /usr/local/lib
After that, I got some errors like this:
Undefined symbols for architecture x86_64:
"__ZN5GiNaC12archive_node6add_exERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_2exE", referenced from:
__ZNK5GiNaC9containerISt6vectorE7archiveERNS_12archive_nodeE in ccEkVJyo.o
"__ZN5GiNaC5basic12read_archiveERKNS_12archive_nodeERNS_9containerINSt7__cxx114listEEE", referenced from:
__ZN5GiNaC9containerISt6vectorE12read_archiveERKNS_12archive_nodeERNS0_INSt7__cxx114listEEE in ccEkVJyo.o
"__ZN5GiNaC6symbolC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", referenced from:
_main in ccEkVJyo.o
"__ZN5GiNaC9containerISt6vectorE8reg_infoE", referenced from:
__ZN5GiNaC9containerISt6vectorE21get_class_info_staticEv in ccEkVJyo.o
"__ZN5GiNaClsERSoRKNS_2exE", referenced from:
_main in ccEkVJyo.o
"__ZNK5GiNaC12archive_node14find_ex_by_locEN9__gnu_cxx17__normal_iteratorIPKNS0_8propertyESt6vectorIS3_SaIS3_EEEERNS_2exERNS_9containerINSt7__cxx114listEEE", referenced from:
__ZN5GiNaC9containerISt6vectorE12read_archiveERKNS_12archive_nodeERNS0_INSt7__cxx114listEEE in ccEkVJyo.o
"__ZNK5GiNaC12archive_node19find_property_rangeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_", referenced from:
__ZN5GiNaC9containerISt6vectorE12read_archiveERKNS_12archive_nodeERNS0_INSt7__cxx114listEEE in ccEkVJyo.o
"__ZNK5GiNaC5basic10eval_ncmulERKSt6vectorINS_2exESaIS2_EE", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC5basic11to_rationalERSt3mapINS_2exES2_NS_10ex_is_lessESaISt4pairIKS2_S2_EEE", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC5basic13contract_withEN9__gnu_cxx17__normal_iteratorIPNS_2exESt6vectorIS3_SaIS3_EEEES8_RS7_", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC5basic13to_polynomialERSt3mapINS_2exES2_NS_10ex_is_lessESaISt4pairIKS2_S2_EEE", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC5basic14subs_one_levelERKSt3mapINS_2exES2_NS_10ex_is_lessESaISt4pairIKS2_S2_EEEj", referenced from:
__ZNK5GiNaC9containerISt6vectorE4subsERKSt3mapINS_2exES4_NS_10ex_is_lessESaISt4pairIKS4_S4_EEEj in ccEkVJyo.o
"__ZNK5GiNaC5basic5matchERKNS_2exERSt3mapIS1_S1_NS_10ex_is_lessESaISt4pairIS2_S1_EEE", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC5basic6normalERSt3mapINS_2exES2_NS_10ex_is_lessESaISt4pairIKS2_S2_EEES9_RNS_9containerINSt7__cxx114listEEE", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
"__ZNK5GiNaC9containerISt6vectorE4infoEj", referenced from:
__ZTVN5GiNaC9containerISt6vectorEE in ccEkVJyo.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
I know that Undefined Symbols
error often comes up because of the link error, but the detailed error messages looks like that these errors are from ginac itself.
I have tried different orders of these -l
parameters, but the errors always exist.
I tried clang
instead of gcc
to compile this file and it works. So I guess I do install the ginac library correctly. But I'm still confused about these errors when using gcc
.
Has anyone met this problem?
I would be very appreciate if anyone could give me some advice!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还遇到了问题:
但是它确实可以使用:
I also had issues using:
but it did work with: