链接到boost ::线程失败

link to boost::thread fails

本文关键字:线程 失败 boost 链接      更新时间:2023-10-16

我正在尝试安装一个名为MGIZA的程序。它用CMAKE编译,需要一些提升库。我使用了命令

cmake .
make

当我运行'make'时,我会收到以下错误:

d4norm.cxx:(.text+0x95b): undefined reference to `boost::system::generic_category()'

和赞。我在cmakelists.txt中插入以下行:

FIND_PACKAGE( Boost 1.41 COMPONENTS system)

它起作用是因为可以编译更多文件,并且上面的警告消失了,但我收到了另一个警告:

main.cpp:(.text+0x7174): undefined reference to `boost::thread::hardware_concurrency()'

尽管我已经在cmakelists中有Find_package(Boost 1.41组件线程)。我在做什么错?

您还需要搜索线程组件:

find_package(Boost 1.41 COMPONENTS thread system)

在boost的较新版本中,您还应针对boost.chrono

链接
find_package(Boost COMPONENTS thread chrono system)

然后,您还需要将可执行文件链接起来,并添加包含:

# Check if everything worked out
if(Boost_FOUND)
  add_executable(main main.cpp) # your executable or library or whatever
  target_link_libraries(main ${Boost_LIBRARIES})
  target_include_directories(main ${Boost_INCLUDE_DIRS})
else()
  # panic
endif()