[CMake] target_link_libraries can't link shared libraries not listed in LD_LIBRARY_PATH
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. 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 *** OS: Ubuntu 11.10 64 bit Compiler: g++ 4.6.1. Cmake 2.8.5 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 ) target_link_libraries(${lib_name} debug ${do_scoring_debug} optimized ${do_scoring} general ${spinx} general rt general dl general pthread general cblas general ${atlas} ) Thank you in advance, Vyacheslav. -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] target_link_libraries can't link shared libraries not listed in LD_LIBRARY_PATH
Hi, On Mon, Apr 23, 2012 at 13:24, Vyacheslav Karamov ubuntul...@yandex.ruwrote: 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 -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] target_link_libraries can't link shared libraries not listed in LD_LIBRARY_PATH
Hi! I just find the solution. The problem was in order how libraries were specified. target_link_libraries(${lib_name} general rt general dl general pthread debug ${do_scoring_debug} optimized ${do_scoring} general ${spinx} general ${cblas} general ${atlas} ) 23.04.2012 16:28, Andreas Pakulat ???: Hi, On Mon, Apr 23, 2012 at 13:24, Vyacheslav Karamov ubuntul...@yandex.ru mailto:ubuntul...@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 -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
Re: [CMake] target_link_libraries can't link shared libraries not listed in LD_LIBRARY_PATH
Hi! I just find the solution. The problem was in order how libraries were specified. target_link_libraries(${lib_name} general rt general dl general pthread debug ${do_scoring_debug} optimized ${do_scoring} general ${spinx} general ${cblas} general ${atlas} ) You don't need the general keyword, specifying just a library will make it be used with any build type. Also you may want to replace general dl with ${CMAKE_DL_LIBS} and general pthread with ${CMAKE_THREAD_LIBS_INIT} for portability. Note that you need find_package(Threads) for the latter to work. Eike -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake