I am generating libs from header-only source files, I have a simple header with 
no dependencies, and a header with boost_filesystem and boost_system 
dependencies.
I am facing linking problems (ld)  against boost, when I link the library to 
the test executable. Tests are in a subdirectory, with an extra CMakeLists.txt. 
With the no-dependency header, I have no problems.
Top CMakeLists.txt:
add_library(histo-header histo-header.h)
set_target_properties(histo-header PROPERTIES LINKER_LANGUAGE CXX)
FILE(COPY histo-header.h DESTINATION include)

test/CMakeLists.txt:
add_executable(test_histo.exe test_histo.cpp)
target_link_libraries(test_histo.exe ${test_libraries})
target_link_libraries(test_histo.exe histo-header)

All good here.

But when I do the same with the library with boost dependencies:
Top CMakeLists.txt:
    find_package(Boost COMPONENTS
            system filesystem
            REQUIRED)
    include_directories(${Boost_INCLUDE_DIRS})
    add_library(histo-header-boost histo-header-boost.h )
    target_link_libraries(histo-header-boost PUBLIC ${Boost_Libraries})
    set_target_properties(histo-header-boost PROPERTIES LINKER_LANGUAGE CXX)
    FILE(COPY histo-header-boost.h DESTINATION include)

test/CMakeLists.txt:
SET( Boost_LIBRARIES ${Boost_LIBRARIES} PARENT_SCOPE )
add_executable(test_histo-boost.exe test_histo-boost.cpp )
target_link_libraries(test_histo-boost.exe ${test_libraries})
target_link_libraries(test_histo-boost.exe histo-header-boost)

I face this error:

CMakeFiles/test_histo-boost.exe.dir/test_histo-boost.cpp.o: In function 
`__static_initialization_and_destruction_0(int, int)':
test_histo-boost.cpp:(.text+0x1c2): undefined reference to 
`boost::system::generic_category()'
test_histo-boost.cpp:(.text+0x1ce): undefined reference to 
`boost::system::generic_category()'
test_histo-boost.cpp:(.text+0x1da): undefined reference to 
`boost::system::system_category()'
collect2: error: ld returned 1 exit status
m

What am I missing here?

So 
                                          
-- 

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

Reply via email to