Build two versions of Poco Lib 1.7.8 and 1.7.9p2 via following command line:
./configure --static --shared --config=Linux
make
build is fine and I got a bunch of .a and .so libraries. Then I coded following snippet code to test 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;
}
Then I compile it using this command line:
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
Finally, I see this link error like this:
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
Then I use "nm" to dump test.o and following following related symbols:
U _ZN4Poco16BadCastExceptionC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEi
U _ZN4Poco16BadCastExceptionD1Ev
U _ZTIN4Poco16BadCastExceptionE
To further debug I dumped libPocoFoundation.a symbol as well. Following are all the symbols with 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
Both Poco lib and my test.cpp are compiled using the same compiler gcc 5.3. And I see all the BadCastException symbols show up in test.o are there in the lib symbol list. Why do I get the link error?
You would need an -llibrary
option (lower-case l
) for the linker to search the library. Uppercase -L
gives the path to search for libraries, but doesn't tell the linker to include everything there.