[CMake] linking with .so w/ non-standard names

Bill Hoffman bill.hoffman at kitware.com
Mon Aug 17 13:08:45 EDT 2009


Kenneth Chang wrote:
> thx, yes, it's 64-bit linux.
> 
> 
So, Brad King is the person who is the expert in the elf linking in 
CMake, and he is on vacation right now.

I did find this comment, which describes pretty much what is going on:

 From cmComputeLinkInformation.cxx:
------------------------------------------------------
Notes about shared libraries with no builtin soname:

Some UNIX shared libraries may be created with no builtin soname.  On
some platforms such libraries cannot be linked using the path to their
location because the linker will copy the path into the field used to
find the library at runtime.

   Apple:    ../libfoo.dylib  ==>  libfoo.dylib  # ok, uses install_name
   SGI:      ../libfoo.so     ==>  libfoo.so     # ok
   AIX:      ../libfoo.so     ==>  libfoo.so     # ok
   Linux:    ../libfoo.so     ==>  ../libfoo.so  # bad
   HP-UX:    ../libfoo.so     ==>  ../libfoo.so  # bad
   Sun:      ../libfoo.so     ==>  ../libfoo.so  # bad
   FreeBSD:  ../libfoo.so     ==>  ../libfoo.so  # bad

In order to link these libraries we need to use the old-style split
into -L.. and -lfoo options.  This should be fairly safe because most
problems with -lfoo options were related to selecting shared libraries
instead of static but in this case we want the shared lib.  Link
directory ordering needs to be done to make sure these shared
libraries are found first.  There should be very few restrictions
because this need be done only for shared libraries without soname-s.
------------------------------------------------------

So, it must be that the library is built with no soname.   Brad will be 
back in a few days, and should have a better idea of how to fix it.  For 
now, you can do one of these:

1. rename the library to have lib in front of it  libthostmduserapi.so
2. Rebuild thostmduserapi.so with an soname
3. Add this to your CMakeLists.txt file:

set(CMAKE_PLATFORM_USES_PATH_WHEN_NO_SONAME FALSE)

before the target_link_library call. But, that might have some bad rpath 
information.

-Bill


More information about the CMake mailing list