通过以下命令行构建两个版本的Poco Lib 1.7.8和1.7.9p2:
./configure --static --shared --config=Linux
make
构建很好,我有一堆.a和.so库。然后我编写了以下片段代码来测试Poco :: Any
#include <iostream>
#include "Poco/Any.h"
int main()
{
Poco::Any data(10);
int i = Poco::AnyCast<int>(data);
std::cout << "Internal data = " << i << std::endl;
return 0;
}
然后我使用以下命令行编译它:
g++ test.cpp -o test -I../poco/poco-1.7.9p2/Foundation/include -L../poco/poco-1.7.9p2/lib/Linux/x86_64/libPocoFoundation.a
最后,我看到这样的链接错误:
test.cpp:(.text._ZN4Poco7AnyCastIiEET_RNS_3AnyE[_ZN4Poco7AnyCastIiEET_RNS_3AnyE]+0x64): undefined reference to `Poco::BadCastException::BadCastException(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
test.cpp:(.text._ZN4Poco7AnyCastIiEET_RNS_3AnyE[_ZN4Poco7AnyCastIiEET_RNS_3AnyE]+0x81): undefined reference to `Poco::BadCastException::~BadCastException()'
test.cpp:(.text._ZN4Poco7AnyCastIiEET_RNS_3AnyE[_ZN4Poco7AnyCastIiEET_RNS_3AnyE]+0x86): undefined reference to `typeinfo for Poco::BadCastException'
collect2: error: ld returned 1 exit status
然后我使用“nm”转储test.o并遵循以下相关符号:
U _ZN4Poco16BadCastExceptionC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi
U _ZN4Poco16BadCastExceptionD1Ev
U _ZTIN4Poco16BadCastExceptionE
为了进一步调试我也转储了libPocoFoundation.a符号。以下是BadCastException的所有符号:
00000000000059e0 T _ZN4Poco16BadCastExceptionaSERKS0_
0000000000005930 T _ZN4Poco16BadCastExceptionC1Ei
0000000000005960 T _ZN4Poco16BadCastExceptionC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi
00000000000059a0 T _ZN4Poco16BadCastExceptionC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_9ExceptionEi
0000000000005980 T _ZN4Poco16BadCastExceptionC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_i
00000000000059c0 T _ZN4Poco16BadCastExceptionC1ERKS0_
0000000000005930 T _ZN4Poco16BadCastExceptionC2Ei
0000000000005960 T _ZN4Poco16BadCastExceptionC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi
00000000000059a0 T _ZN4Poco16BadCastExceptionC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_9ExceptionEi
0000000000005980 T _ZN4Poco16BadCastExceptionC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_i
00000000000059c0 T _ZN4Poco16BadCastExceptionC2ERKS0_
0000000000001260 T _ZN4Poco16BadCastExceptionD0Ev
0000000000000c60 T _ZN4Poco16BadCastExceptionD1Ev
0000000000000c60 T _ZN4Poco16BadCastExceptionD2Ev
0000000000000910 T _ZNK4Poco16BadCastException4nameEv
0000000000003300 T _ZNK4Poco16BadCastException5cloneEv
0000000000003350 T _ZNK4Poco16BadCastException7rethrowEv
0000000000000920 T _ZNK4Poco16BadCastException9classNameEv
0000000000000000 V _ZTIN4Poco16BadCastExceptionE
0000000000000000 V _ZTSN4Poco16BadCastExceptionE
0000000000000000 V _ZTVN4Poco16BadCastExceptionE
U _ZN4Poco16BadCastExceptionC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi
U _ZN4Poco16BadCastExceptionD1Ev
U _ZTIN4Poco16BadCastExceptionE
U _ZN4Poco16BadCastExceptionC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi
U _ZN4Poco16BadCastExceptionD1Ev
U _ZTIN4Poco16BadCastExceptionE
U _ZN4Poco16BadCastExceptionC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi
U _ZN4Poco16BadCastExceptionD1Ev
U _ZTIN4Poco16BadCastExceptionE
Poco lib和我的test.cpp都是使用相同的编译器gcc 5.3编译的。我看到在test.o中显示的所有BadCastException符号都存在于lib符号列表中。为什么我会收到链接错误?
答案 0 :(得分:0)
您需要-llibrary
选项(小写l
)才能让链接器搜索库。大写-L
给出了搜索库的路径,但没有告诉链接器包含所有内容。