[Cmake] Static library linking

William A. Hoffman billlist at nycap.rr.com
Thu, 15 Apr 2004 12:25:23 -0400


This is a tricky problem.  The linker will prefer shared over static
if there are two libraries.   CMake splits the full path into
-L and -l because on some OS's a full path to a library on the link
line has some unexpected side effects ( putting the full path to
a shared library into the executable, linking all the .o files from
the .a)

So, the only way to get around this is to copy the postgres static library
into a different directory and link with that one.

-Bill


At 12:02 PM 4/15/2004, Iker Arizmendi wrote:
>I'm trying to have an executable link against the
>static Postgres library, but for some reason CMake
>insists on generating a link line that refers to
>the shared version though I specify otherwise.
>
>The following CMake snippet:
>
>   INCLUDE_DIRECTORIES(${asrdb_SOURCE_DIR}/src)
>   ADD_EXECUTABLE(dbadmin dbadmin.cpp dbadmin-args.cpp)
>   MESSAGE(STATUS "Postgres Library: ${PGSQL_STATIC_LIB}")
>   TARGET_LINK_LIBRARIES(dbadmin asrdb ${PGSQL_STATIC_LIB})
>
>where PGSQL_STATIC_LIB points to "/usr/lib/libpq.a" and
>asrdb is my own static library which uses functions exported
>by libpq.a. This results in the following output:
>
>Building dependencies. cmake.depends...
>/usr/bin/cmake -S/home/iker/network/proj/asrdb/dbadmin -O/home/iker/proj/build/asrdb/dbadmin -H/home/iker/network/proj/asrdb -B/home/iker/proj/build/asrdb
>-- Postgres Library: /usr/lib/libpq.a
>
>...
>...
>
>Building object file dbadmin.o...
>/usr/bin/g++ -o dbadmin.o  -g -fno-inline -Wall -fmessage-length=0 -I/home/iker/network/proj/asrdb/dbadmin -I/home/iker/network/proj/asrdb/src    -c /home/iker/network/proj/asrdb/dbadmin/dbadmin.cpp
>
>Building object file dbadmin-args.o...
>/usr/bin/g++ -o dbadmin-args.o  -g -fno-inline -Wall -fmessage-length=0 -I/home/iker/network/proj/asrdb/dbadmin -I/home/iker/network/proj/asrdb/src    -c /home/iker/network/proj/asrdb/dbadmin/dbadmin-args.cpp
>
>PROBLEM HERE...
>
>Building executable /home/iker/proj/build/asrdb/dbadmin/dbadmin...
>/usr/bin/g++     -g -fno-inline -Wall -fmessage-length=0 -fPIC dbadmin.o dbadmin-args.o    -o /home/iker/proj/build/asrdb/dbadmin/dbadmin -rdynamic -L/home/iker/proj/build/asrdb/src -lasrdb -lpq -Wl,-rpath,/home/iker/proj/build/asrdb/src
>
>
>The link line above refers to "-lpq" instead of "/usr/lib/libpq.a".
>Is CMake doing the wrong thing here? Other posts on the mailing
>list suggest this is the way to do this.
>
>Iker
>
>-- 
>Iker Arizmendi
>AT&T Labs - Research
>Speech and Image Processing Lab
>e: iker at research.att.com
>w: http://research.att.com
>
>_______________________________________________
>Cmake mailing list
>Cmake at www.cmake.org
>http://www.cmake.org/mailman/listinfo/cmake