我想编写一个简单的测试应用程序,使用我写的库。这在其他机器上编译并运行良好。链接器告诉我它不能解析符号,但它们在那里?
我有libroller.so可在/ usr/lib。我编译main.cpp中这样:
g++ -g3 -Wall -I"../../" -lrt -lroller -o rap main.o
它抱怨许多错误,如:
/....../main.cpp:51: undefined reference to `Log::i(char const*, ...)'
但是,我知道,这些在此所以存在:
nm -Ca /usr/lib/libroller.so | grep "Log::i"
00000000001f5d50 T Log::i(char const*, ...)
0000000000149530 W Log::i(std::string const&)
两者都是64位:
file /usr/lib/libroller.so
/usr/lib/libroller.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped
file main.o
main.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
UNL ike GCC and ld can't find exported symbols...but they're there!我很确定这些符号是被定义的。同样的.so与另一个使用一些相同的符号。
编辑/回答:对象的顺序很重要。在库之前放置main.o是必要的。我猜连接器没有未解决的符号来处理,直到它到达main.o - 哪个是其列表中的最后一个对象。我仍然对为什么这个工作在其他机器上许多个月有点糊涂了......
你的问题是[this one] [1]的重复,并有相同的答案。 [1]:http://stackoverflow.com/questions/8380087/boost-1-48-linking-issue-with-gcc-4-6-1 –
感谢。我做了搜索,我保证:)搜索“未解决”和“gcc”会出现大量不相关的答案... – notlesh
[为什么库链接的顺序有时会导致GCC错误?](https: //stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc) –