6

I'm trying to link to static versions of the POCO C++ libs like this:

g++ BCCMain.o -L$_POCO_LIBS -Wl,-Bstatic $_POCO_LIBS/libPocoFoundation.a $_POCO_LIBS/libPocoUtil.a $_POCO_LIBS/libPocoXML.a $_POCO_LIBS/libPocoJSON.a -Wl,-Bdynamic -o BCMain

Unfortunatelly this gives errors about some undefined references to symbols like:

Poco::Logger::get(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)

even though Poco::Logger::get(std::string const&) actually IS defined in libPocoFoundation.a.

Now if I try to link to a shared version of the foundation lib it works:

g++ BCCMain.o -L$_POCO_LIBS -Wl,-Bstatic $_POCO_LIBS/libPocoFoundation.a $_POCO_LIBS/libPocoUtil.a $_POCO_LIBS/libPocoXML.a $_POCO_LIBS/libPocoJSON.a -Wl,-Bdynamic -lPocoFoundation -o BCMain

Static and shared versions of the libs have the same symbols so I find it hard to figure what I'm doing wrong.

Ubuntu/Linaro. g++ 4.6.3

data
  • 2,563
  • 1
  • 21
  • 25
gregee123
  • 321
  • 3
  • 6

2 Answers2

18

My experience is that the order of linking the Poco libraries is important when statically linked. Seems important Foundation to be the last one.

The order that works for me is:

  1. Util
  2. Net
  3. XML
  4. Foundation
i_papp
  • 181
  • 1
  • 3
  • Gah! Thank you, this was it! – Cameron Dec 08 '14 at 18:02
  • Yes, static linking order with gcc is important, and the internal dependencies between those libs must be taken into account. It is not just a POCO issue, but a general behavior in gcc static linking. In this case Util depends on XML (you can check it in the code), for example, and all libs depend on Foundation. Independent libs come first, and the requirements of those libs should be after them. – drodri Aug 27 '15 at 23:35
  • 3
    Also there is PocoJSON which should be between Util and Net libraries. – Bogolt Apr 17 '16 at 18:51
1

I managed to solve this by separating compiling and linking. Here is what mine looks like:

Compile: g++ -c -std=c++0x -ggdb -I/home/bbogart/src/of_v0071_linux64_release/libs/poco/includepkg-config opencv --cflags*.cpp

link: g++ *.o -L/home/bbogart/src/of_v0071_linux64_release/libs/poco/lib/linux64/ -lPocoNet -lPocoUtil -lPocoFoundation -lopencv_gpupkg-config opencv --libs-o cameraGrabber

Note that you omit the "lib" and ".a" from lib names.

b..
  • 281
  • 3
  • 19