我使用cmake进行带有提升的项目,我已经根据需要设置了boost信号,并且cmake说明了它找到了它,但是当我编译项目时,我收到链接错误。
我可以使用链接器指令集(CMAKE_EXE_LINKER_FLAGS -lboost_signals)来解决它 这似乎与它应该做的相反。有人可以提出更好的方法吗?感谢
在CMakeLists.txt
中 IF(UNIX)
find_package(Boost COMPONENTS system filesystem random regex signals thread program_options date_time REQUIRED)
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} )
ENDIF()
运行cmake:
$ cmake ../
-- Boost version: 1.49.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- random
-- regex
-- signals
-- thread
-- program_options
-- date_time
-- Configuring done
-- Generating done
-- Build files have been written to: /home/me/myproject/build
链接错误:
/usr/bin/ld: /usr/local/lib/libwt.so: undefined reference to symbol '_ZN5boost7signals9trackableD2Ev'
/usr/bin/ld: note: '_ZN5boost7signals9trackableD2Ev' is defined in DSO /usr/lib/libboost_signals.so.1.49.0 so try adding it to the linker command line
/usr/lib/libboost_signals.so.1.49.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
答案 0 :(得分:0)
Boost Signals不是仅限标头的库。除了给出include目录之外,你还需要告诉CMake链接它。
add_executable(MyProgram [...] )
target_link_libraries(MyProgram ${Boost_LIBRARIES})
如果您计划在Windows上构建,您可能还想禁用自动链接:
add_definitions(-DBOOST_ALL_NO_LIB)
请注意,Boost Signals已被弃用,并由Signals2取代,consider using Signals2 instead实际上是一个仅限标头的库。如果由您决定,{{3}}。