Guido W. wrote:
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?
You should be using the full path to the libraries in
target_link_library. The link_directories must come before the target
is added for it to take effect. But the full path should be used. You
can also add to where cmake search by setting the environment variable
CMAKE_LIBRARY_PATH so it can find the libs you want.
-Bill
_______________________________________________
CMake mailing list
[email protected]
http://www.cmake.org/mailman/listinfo/cmake