CMake linking Boost: cannot find -lboost_program_options

CMake linking Boost: cannot find -lboost_program_options

本文关键字:-lboost program options find cannot linking Boost CMake      更新时间:2023-10-16

我想在Linux上使用C 中的命令行标志来使用Boosts支持。我使用cmake来构建应用程序,但是我遇到了一个错误"找不到-lboost_program_options"。库BOOST_PROGRAGIN_OPTIONS是使用BJAM独立构建的,库位于Boost目录的舞台/LIB子目录中。

有什么作用:一种解决方案是使用link_directories添加阶段/lib库,但是cmake手册状态:

请注意,此命令很少需要。find_package()返回的库位置和find_library()是绝对路径。

,这不应该是内在的。

我想工作的东西:

使用find_package应该足够了,但这是不起作用的,这是cmakelists:

cmake_minimum_required(VERSION 3.6)
project(inp_manipulation)
set(CMAKE_CXX_STANDARD 11)
include_directories(includes lib/boost_1_62_0 lib/)
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "lib/boost_1_62_0")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "lib/boost_1_62_0/stage/lib")
find_package(Boost 1.62.0)
include_directories(${Boost_INCLUDE_DIR})
file(GLOB SOURCES *.cpp)
set(MAIN_FILE main.cpp)
set(SOURCE_FILES ${SOURCES})
add_executable(inp_manipulation ${MAIN_FILE} ${SOURCE_FILES} )
target_link_libraries(inp_manipulation -static-libgcc -static-libstdc++ boost_program_options)

问题

cmakelists中的错误在哪里?

预先感谢!

首先,您必须告诉cmake您需要boost的特定组件库:

find_package(Boost 1.62.0 COMPONENTS program_options)

第二,始终使用boostfind.cmake

的输出变量
target_link_libraries(inp_manipulation -static-libgcc -static-libstdc++ ${Boost_LIBRARIES})

文档在这里:https://cmake.org/cmake/help/v3.0/module/findboost.html

输出变量为:

boost_found-如果找到标题和请求的库

boost_include_dirs - boost Include Directories

BOOST_LIBRARY_DIRS - boost库的链接目录

boost_libraries - 要链接的boost组件库

etc