boost c linux,关于C ++:CMake找不到Boost Linux

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

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返回:

-找不到助推器

但是MESSAGE($ {Boost_INCLUDE_DIR})返回一个目录。

但是,构建失败。

正如您希望看到的那样,我已尝试遵循此相关问题的答案:

未定义对`boost :: program_options :: options_description :: m_default_line_length的引用,但未解决问题。

我在带有cmake 3.11的Ubuntu 16.04上

和提升位于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

除了单词Could NOT find Boost,还应该有其他描述问题的内容。 同样,如果在查找Boost时遇到问题,第一步可能是启用Boost_DEBUG:在find_package()调用之前添加行set(Boost_DEBUG ON)并显示结果日志。

顺便说一句,您可以使用目标属性来设置C ++标准,而不是设置-std=c++0x:cmake.org/cmake/help/v3.1/prop_tgt/CXX_STANDARD.html

您不仅需要安装标头,还需要安装这些库。

sudo apt install libboost-program-options-dev

应该解决您的问题。

现在它正在工作,我认为增强构建可以解决问题:

./bootstrap.sh --prefix=path where to install

./b2 install

似乎CMake / FindBoost找不到Boost.ProgramOptions的库文件。 验证您在输出中显示的名称确实存在于系统中的某个位置,如果存在,请确保FindBoost在该位置查找。

你可能感兴趣的:(boost,c,linux)