[SOLVED] Static Link POCO Libraries

Please post support and help requests here.
Posts: 3
Joined: 20 Oct 2013, 04:47

[SOLVED] Static Link POCO Libraries

Postby CodeHugger » 14 Nov 2013, 18:03

I'm having problems statically linking my Poco libraries.

Red Hat Linux 5.8
GCC version 4.1.2 20080704 (RedHat 4.1.2-52)
IDE Vim (also tried NetBeans using my own Makefile with same result)
Using Data/ODBC

I static compiled my Poco libraries with this configuration:
./configure --static --no-tests --no-samples --omit=NetSSL_OpenSSL,Crypto,Data/MySQL
and it completed without errors.
I now have the .a libraries. Using the two step compile/link, here are some of the linker commands that I have tried:

g++ -L/usr/local/lib *.o -o CraDaemon -lodbc -Wl,-Bstatic -lPocoData -lPocoDataODBC cannot find lgcc_s. Yes it exists (.so version) and all symbolic links are good. --verbose shows that its looking for the .a version. To prevent this, I added dynamic at the end like this:
g++ -L/usr/local/lib *.o -o CraDaemon -lodbc -Wl,-Bstatic -lPocoData -lPocoDataODBC -Wl,-Bdynamic This ensures only the Poco libraries are static linked and the system libs are dynamically linked. This resulted in the complete list of Poco references as undefined.
g++ -L/usr/local/lib *.o -lodbc -Wl,-Bstatic -lPocoData -lPocoDataODBC -lPocoFoundation -Wl,-Bdynamic Added -lPocoFoundation just because I noticed some of the undefined ref were defined here... still get all poco references as undefined
g++ -L/usr/local/lib *.o -static -lodbc -lPocoData -lPocoDataODBC using -static instead of -Wl,-Bstatic appeared to work but it dynamically linked the Poco Libraries instead of static linking them ????
g++ -L/usr/local/lib *.o -lodbc -lPocoData -lPocoDataODBC This is my standard link command that works to dynamically link everything. I tried it again after renaming the shared Poco libraries (forcing the use of .a versions) but this also resulted in the full list of undefined Poco references
I also tried shifting the order of everything in the link command, I must have tried every combination.

I have narrowed the problem down to the lPocoDataODBC library. I can link all others statically like this but when I include -lPocoDataODBC, I get unresolved references.
g++ -L/usr/local/lib -Wl,-Bstatic -lodbc -lPocoData -Wl,-Bdynamic -lPocoDataODBC ---> works only because I'm not statically linking that last library
NOTE* I can add -lPocoFoundation, -lgcc, and -lstdc++ to the static linked side and it still links without error but does not help me statically link that last library (-lPocoDataODBC).

***UPDATE #2***
The link command in the first update above only appears to statically link all but -lPocoDataODBC. I found that when a library (-lPocoDataODBC) is dynamically linked, so are all of it's dependencies. -lPocoDataODBC has a dependency on all the libraries in the linker command above plus a couple more (libPocoFoundation and libodbcinst). UUUGGG.... That means EVERYTHING is still being dynamically linked. I verified this by moving the executable to another system and running it....it complained that it did not have each of those 'shared' libraries. Back to square one.

Both of the responses below were correct. The working link command is below. Sorry for the slow update: THANK YOU BOTH VERY MUCH!!!
g++ -L/usr/local/lib *.o -o CraDaemon -Wl,-Bstatic -lPocoDataODBC -lPocoData -lPocoFoundation -Wl,-Bdynamic -lodbc
:D Jason
Last edited by CodeHugger on 19 Dec 2013, 16:42, edited 3 times in total.

Posts: 89
Joined: 29 Mar 2013, 12:11

Re: Static Link POCO Libraries

Postby gregee123 » 15 Nov 2013, 13:42

When linking statically the order of the libs in the command line is essential. You need to put libs that depend on other libs first and then those that provide the required symbols. Try it like this: -lPocoDataODBC -lPocoData -lodbc.

In case it doesn't do the trick please post your full command line and linker output.
currently using: 1.6.0

Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: Static Link POCO Libraries

Postby guenter » 15 Nov 2013, 14:04

If you link with PocoDataODBC and PocoData, you must also link PocoFoundation (in that order).

Return to “Support”

Who is online

Users browsing this forum: No registered users and 3 guests