[CMake] target_link_libraries can't link shared libraries not listed in LD_LIBRARY_PATH
Andreas Pakulat
apaku at gmx.de
Mon Apr 23 09:28:44 EDT 2012
Hi,
On Mon, Apr 23, 2012 at 13:24, Vyacheslav Karamov <ubuntulist at yandex.ru>wrote:
> Hi All!
>
> I have a problem with target_link_libraries. It can't link with shared
> libraries not from directory listed in LD_LIBRARY_PATH.
> 1. When I try to link shared library with the full path obtained from
> find_library, my library is passed to gcc without -l option as ordinary
> object file.
>
What is the problem with linking the absolute path of the shared library?
This should just work
> 2. When I try to link by specifying short name "cblas" I've got the error
> message:
>
> Linking CXX shared library ../../sndcompare/amd64sse3/**libsndcompared.so
> /usr/bin/ld: cannot find -lcblas
> collect2: ld returned 1 exit status
> make[2]: *** [../../sndcompare/amd64sse3/**libsndcompared.so] Error 1
> make[1]: *** [CMakeFiles/sndcompare.dir/**all] Error 2
> make: *** [all] Error 2
> *** Failed ***
>
This is because the linker does not know the directory where to search for
the library.
> add_library(${lib_name} SHARED
> ${io_files}
> ${utils_files}
> ${tech_independ_files}
> ${other_files}
> )
>
> find_library(atlas
> NAME atlas
> PATHS ${CMAKE_CURRENT_SOURCE_DIR}/${**CMAKE_SYSTEM_NAME}/atlas/${**
> arch}/lib
> DOC "Atlas library"
> )
>
> find_library(cblas
> NAME cblas
> PATHS ${CMAKE_CURRENT_SOURCE_DIR}/${**CMAKE_SYSTEM_NAME}/atlas/${**
> arch}/lib
> DOC "Cblas library"
> )
>
> link_directories(
> ${CMAKE_CURRENT_SOURCE_DIR}/${**CMAKE_SYSTEM_NAME}/atlas/${**arch}/lib
> ${CMAKE_CURRENT_SOURCE_DIR}/..**/../Sphinx/sphinxbase/${CMAKE_**
> SYSTEM_NAME}/${arch}/lib
> )
>
link_directories is not needed at all here or should not be needed. Just
make sure to pass ${cblas} and ${atlas} to
target_link_libraries. If that produces errors please provide the exact
error message.
Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20120423/63e81276/attachment-0001.htm>
More information about the CMake
mailing list