CMake:未定义引用boost库 [英] CMake: undefined reference to boost library

查看:1095
本文介绍了CMake:未定义引用boost库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下方式添加了boost:

 设置(Boost_USE_STATIC_LIBS ON)
设置(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED)
include_directories($ {Boost_INCLUDE_DIR})

project(APP C CXX)
add_executable(APP src.cpp )
target_link_libraries(APP $ {Boost_LIBRARIES})

  demo.cpp :(。text + 0x3d3):未定义引用`boost :: system :: generic_category 

我检查了拼写(Boost_LIBRARIES和BOOST_LIBRARIES),但是没关系。



我使用包boost-devel在Fedora中安装boost。

解决方案 https://github.com/Kitware/CMake/blob/master/Modules/FindBoost.cmake#L1775 =nofollow>源代码, Boost_LIBRARIES 根据传递给 find_package 的组件列表填充。尝试:

  find_package(Boost REQUIRED COMPONENTS system)

您还应该使用导入的目标:

 设置(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED COMPONENTS system)

#调用include_directories现在没有用了:
# Boost ::系统导入目标使用下面
#嵌入include目录

项目(APP C CXX)
add_executable(APP src.cpp)
target_link_libraries :: system)


I added boost via this:

set(Boost_USE_STATIC_LIBS        ON) 
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)
find_package(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIR})

project(APP C CXX)
add_executable(APP src.cpp)
target_link_libraries(APP ${Boost_LIBRARIES})

And when I compiled source, I got:

demo.cpp:(.text+0x3d3): undefined reference to `boost::system::generic_category()'

I checked spelling (Boost_LIBRARIES vs BOOST_LIBRARIES) but it's ok.

I installed boost in Fedora with the package boost-devel.

解决方案

Looking in the source code, Boost_LIBRARIES is filled according to the component list passed to find_package. Try:

find_package(Boost REQUIRED COMPONENTS system)

You should also use imported targets:

set(Boost_USE_STATIC_LIBS        ON)
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)
find_package(Boost REQUIRED COMPONENTS system)

# the call to include_directories is now useless:
# the Boost::system imported target used below
# embeds the include directories

project(APP C CXX)
add_executable(APP src.cpp)
target_link_libraries(APP Boost::system)

这篇关于CMake:未定义引用boost库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆