If it is an external library you will need to look at creating import libraries and packaging targets ( http://www.cmake.org/cmake/help/v3.1/manual/cmake-packages.7.html#manual:cmake-packages(7) ).
On Tue, Mar 3, 2015 at 8:10 PM, Pablo Hernández < [email protected]> wrote: > I want to generate in cmake a header-only library from header.h, that > depends on libboost_system and filesystem. I can compile the library > without problems with: > > find_package(Boost COMPONENTS > system filesystem > REQUIRED) > include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) > add_library(mylib SHARED header.h) > target_link_libraries(mylib PUBLIC ${Boost_LIBRARIES}) > set_target_properties(mylib PROPERTIES LINKER_LANGUAGE CXX) > > But when I link to mylib elsewhere, it fails finding the boost library > with a ld error. > The failure makes sense, but I don't know how to solve it in CMake. How do > I "store" the boost dependency on mylib? So I don't have to worry about > finding the boost library in other external project? > > I am using cmake 3.2 > When I use it in other project, the linker is not able to find the boost > library: > target_link_libraries(newproject.exe ${external_mylib}) > > undefined reference to symbol > '_ZN5boost6system15system_categoryEv'/PATH/TO/libboost_system-mt-d.so.1.57.0: > error adding symbols: DSO missing from command line > collect2: error: ld returned 1 exit status > > It is solved if I explicitly link again to the Boost_LIBRARIES. > target_link_libraries(newproject.exe ${external_mylib} ${Boost_LIBRARIES)) > > > This doesn't avoid finding again the boost_libraries, maybe the solution > is to put the boost_libraries in the environment variable LD_LIBRARY_PATH? > Can I avoid relinking to boost somehow? > > > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at > http://www.kitware.com/opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > http://public.kitware.com/mailman/listinfo/cmake >
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake
