[odb-users] Unable to build with static libraries

Boris Kolpackov boris at codesynthesis.com
Thu Oct 11 05:55:49 EDT 2012


Hi Chris,

Chris Richards <chris.richards at yellowfeather.co.uk> writes:

> I should point out that I would like to link against the static  
> libraries for Boost and MySQL.

The autotools build system doesn't really support such selective
static linking (i.e., some libraries should be linked statically
while other dynamically). In fact, with some linkers you won't
even be able to do that unless a static library is the only
option.

With GNU ld, you can use the -Bstatic and -Bdynamic options to
specify which libraries should be linked statically and which
dynamically.

Here is how you can build the hello example to link to all the
ODB, Boost, and MySQL libraries statically and to everything
else dynamically:

odb -d mysql --generate-query --generate-schema person.hxx
g++ -c -DDATABASE_MYSQL person-odb.cxx driver.cxx
g++ -o driver driver.o person-odb.o -Wl,-Bstatic -lodb-mysql -lodb -lmysqlclient_r -Wl,-Bdynamic -lpthread -lz

In your case (CentOS/RH/Fedora), you will also need to add 
-L/usr/lib/mysql (or -L/usr/lib64/mysql) to the last command.

Boris



More information about the odb-users mailing list