相关疑难解决方法(0)

什么是未定义的引用/未解析的外部符号错误,我该如何解决?

什么是未定义的参考/未解决的外部符号错误?什么是常见原因以及如何修复/预防它们?

随意编辑/添加您自己的.

c++ c++-faq linker-errors unresolved-external undefined-reference

1418
推荐指数
32
解决办法
52万
查看次数

链接静态C库和C++代码时出现"未定义的引用"错误

我有一个测试文件(仅用于链接测试),其中我使用我自己的/ 库调用来重载new/ delete运算符.但是在链接静态库时,我一直得到"未定义的引用"错误,即使我改变了和的顺序.但是一切都适用于连接这个库的其他C程序.我对这个问题很困惑,并且感谢任何线索.mallocfreelibxmalloc.atest.o-lxmalloc

错误消息:

g++ -m64 -O3 -I/usr/include/ethos -I/usr/include/nacl/x86_64 -c -o test.o test.cpp
g++ -m64 -O3 -L. -o demo test.o -lxmalloc
test.o: In function `operator new(unsigned long)':
test.cpp:(.text+0x1): undefined reference to `malloc(unsigned long)'
test.o: In function `operator delete(void*)':
test.cpp:(.text+0x11): undefined reference to `free(void*)'
test.o: In function `operator new[](unsigned long)':
test.cpp:(.text+0x21): undefined reference to `malloc(unsigned long)'
test.o: In function `operator delete[](void*)':
test.cpp:(.text+0x31): undefined reference to `free(void*)'
test.o: In function `main':
test.cpp:(.text.startup+0xc): undefined reference …
Run Code Online (Sandbox Code Playgroud)

c c++ static-libraries

33
推荐指数
1
解决办法
5万
查看次数