gpt4 book ai didi

c++ - cmake 找不到 boost linux

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:06:21 25 4
gpt4 key购买 nike

我正在尝试使用来自 Boost 的 program_options 库。但是,CMake 可以也不能找到 boost ...我做错了什么?

CMakeLists.txt:

cmake_minimum_required (VERSION 3.8)
project(myProject)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "-std=c++0x -g -Wall -O3")

set(CMAKE_CXX_FLAGS_DEBUG "-g")

include_directories ("${PROJECT_BINARY_DIR}")

SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "~/Documents/test/myProject/lib/boost_1_65_0")
SET(CMAKE_BOOST_ROOT ${CMAKE_BOOST_ROOT} "~/Documents/test/myProject/lib/boost_1_65_0")
#SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "lib/boost_1_65_0/stage/lib")
include_directories(lib/boost_1_65_0/boost)

FIND_PACKAGE(Boost 1.65.0 COMPONENTS program_options )
MESSAGE(${Boost_INCLUDE_DIR})

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})

add_executable (myProject main.cpp)


TARGET_LINK_LIBRARIES( myProject LINK_PUBLIC ${Boost_LIBRARIES} -static-libgcc -static-libstdc++ pthread )

FIND_PACKAGE 返回:
-- 找不到 Boost
但是 MESSAGE(${Boost_INCLUDE_DIR}) 返回一个目录..

尽管如此,构建还是失败了。正如您所希望看到的那样,我已尝试遵循此相关问题的答案: undefined reference to `boost::program_options::options_description::m_default_line_length'但没有解决问题。

我在 Ubuntu 16.04 上使用 cmake 3.11和 boost 位于 lib/boost_1_65_0

编辑:添加行按照 Tsyvarev 的建议在 find_package() 之前设置(Boost_DEBUG ON)返回以下输出:

-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1121 ] _boost_TEST_VERSIONS = 1.67.0;1.67;1.66.0;1.66;1.65.1;1.65.0;1.65
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1123 ] Boost_USE_MULTITHREADED = TRUE
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1125 ] Boost_USE_STATIC_LIBS =
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1127 ] Boost_USE_STATIC_RUNTIME =
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1129 ] Boost_ADDITIONAL_VERSIONS =
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1131 ] Boost_NO_SYSTEM_PATHS =
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1199 ] Declared as CMake or Environmental Variables:
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1201 ] BOOST_ROOT =
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1203 ] BOOST_INCLUDEDIR =
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1205 ] BOOST_LIBRARYDIR =
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1207 ] _boost_TEST_VERSIONS = 1.67.0;1.67;1.66.0;1.66;1.65.1;1.65.0;1.65
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1306 ] location of version.hpp: /home/me/Documents/test/myProject/lib/boost_1_65_0/boost/version.hpp
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1330 ] version.hpp reveals boost 1.65.0
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1416 ] guessed _boost_COMPILER = -gcc54
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1426 ] _boost_MULTITHREADED = -mt
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1502 ] _boost_RELEASE_ABI_TAG = -
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1504 ] _boost_DEBUG_ABI_TAG = -d
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1567 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = /home/me/Documents/test/myProject/lib/boost_1_65_0/lib;/home/me/Documents/test/myProject/lib/boost_1_65_0/../lib;/home/me/Documents/test/myProject/lib/boost_1_65_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib_boost_LIBRARY_SEARCH_DIRS_DEBUG = /home/me/Documents/test/myProject/lib/boost_1_65_0/lib;/home/me/Documents/test/myProject/lib/boost_1_65_0/../lib;/home/me/Documents/test/myProject/lib/boost_1_65_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1756 ] Searching for PROGRAM_OPTIONS_LIBRARY_RELEASE: boost_program_options-gcc54-mt-1_65;boost_program_options-gcc54-mt;boost_program_options-mt-1_65;boost_program_options-mt;boost_program_options
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1809 ] Searching for PROGRAM_OPTIONS_LIBRARY_DEBUG: boost_program_options-gcc54-mt-d-1_65;boost_program_options-gcc54-mt-d;boost_program_options-mt-d-1_65;boost_program_options-mt-d;boost_program_options-mt;boost_program_options
-- [ /usr/local/share/cmake-3.11/Modules/FindBoost.cmake:1883 ] Boost_FOUND = 1
-- Could NOT find Boost
Boost version: 1.65.0
Boost include path: /home/me/Documents/test/myProject/lib/boost_1_65_0
Could not find the following Boost libraries:
boost_program_options
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.
/home/me/Documents/test/myProject/lib/boost_1_65_0

最佳答案

您不仅需要安装 header ,还需要安装库。

sudo apt install libboost-program-options-dev 

应该可以解决您的问题。

关于c++ - cmake 找不到 boost linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49688533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com