[CMake] Need help using libraries in non-standard locations
Guido W.
guido-cm at unknownsite.de
Mon Jan 22 12:27:11 EST 2007
Hi,
I'm trying to write a CMakeLists.txt for a small program that needs to use the
Sybase client libraries. These libraries are often in different locations, on
my system they are in /opt/sybase/ase/OCS-15_0/lib. So, my first thought was
to write something like this:
[...]
ADD_LIBRARY (dbconns SHARED ${DBCONNS_SRC})
FIND_LIBRARY (SYBLIB15 NAMES sybct PATHS
$ENV{SYBASE}/$ENV{SYBASE_OCS} /opt/sybase/OCS-15_0 /opt/sybase/ase/OCS-15_0
PATH_SUFFIXES /lib)
IF(NOT SYBLIB15)
MESSAGE (FATAL_ERROR "Sybase libraries not found")
MESSAGE ("Sybase libraries found in ${SYBLIB15}")
LINK_DIRECTORIES (${SYBLIB15})
TARGET_LINK_LIBRARIES (dbconns sybtcl sybintl sybcomn sybct sybcs)
[...]
This didn't work. The output from that MESSAGE command was:
Sybase libraries found in /opt/sybase/ase/OCS-15_0/lib/libsybct.so
So, the output from FIND_LIBRARY was the complete path to the file I told it
to look for and not, as I was expecting, just the directory in which the file
was found. (BTW, why is that so? What am I to do with that output anyway? I
can't use it for either LINK_DIRECTORIES or TARGET_LINK_LIBRARIES...)
Anyway, I went on to do something like this instead:
[...]
FIND_PATH (SYB15_LIBDIR libsybct.so PATHS
$ENV{SYBASE}/$ENV{SYBASE_OCS}/lib /opt/sybase/OCS-15_0/lib /opt/sybase/ase/OCS-15_0/lib)
MESSAGE ("Sybase libraries found in ${SYB15_LIBDIR}")
[...]
LINK_DIRECTORIES (${SYB15_LIBDIR})
[...]
Okay, so this obviously sucks, because it's not portable and doesn't work with
static libraries.
Also, it _still_ doesn't work - the compiler can't find the library when
linking.
This is how the linker commandline looks like when running make VERBOSE=1:
/usr/bin/c++ -fPIC -shared -Wl,-soname,libdbconns.so -o libdbconns.so \
"CMakeFiles/dbconns.dir/dbconn.o" "CMakeFiles/dbconns.dir/dbconnfactory.o" \
"CMakeFiles/dbconns.dir/dbconnpg.o" "CMakeFiles/dbconns.dir/dbconnsyb.o" \
-lsybtcl -lsybintl -lsybcomn -lsybct -lsybcs
/usr/lib/gcc-lib/i586-suse-linux/3.3.5/../../../../i586-suse-linux/bin/ld: \
cannot find -lsybtcl
collect2: ld returned 1 exit status
There is no -L or -Wl,-R anywhere in there. It looks like cmake is just
ignoring the LINK_DIRECTORIES command...
Can anyone help me with this?
Guido W.
More information about the CMake
mailing list