似乎有很多 CMake 无法找到 Boost 的问题。但是,我发现没有一个解决方案对我有用。所以也许我可以打印我的详细信息,看看是否有人能发现这个问题?
我在 Parallels VM 上使用 Ubuntu 18.04。我使用以下方法安装了 Boost 1.73:
sudo add-apt-repository ppa:mhier/libboost-latest
sudo apt update
sudo apt install libboost1.73-dev
因为我想要 1.73(不是 Ubuntu 的 libboost-dev-all 的默认版本)。
我还安装了 CMake 3.18.1,使用方法如下:
sudo snap install --classic cmake
我的CMakeLists.txt:
cmake_minimum_required(VERSION 3.17)
project(myproj LANGUAGES CXX)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(Boost_DEBUG 1)
set(Boost_USE_MULTITHREADED ON)
set(Boost_ADDITIONAL_VERSIONS 1.66.0 1.66 1.73)
SET(Boost_USE_STATIC_LIBS NO)
# ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
FIND_PACKAGE(Boost 1.66 COMPONENTS program_options regex filesystem REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
add_executable(myproj src/main.cpp src/file0.cpp src/file1.cpp)
target_include_directories(myproj PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/)
set_target_properties(myproj PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "CXX")
TARGET_LINK_LIBRARIES(myproj Boost::program_options Boost::regex Boost::filesystem)
install(TARGETS ${PROJECT} DESTINATION bin)
以下是运行 cmake 的输出:
> cmake .
-- The CXX compiler identification is GNU 9.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1491 ] _boost_TEST_VERSIONS = "1.66.0;1.66;1.73;1.73.0;1.73;1.72.0;1.72;1.71.0;1.71;1.70.0;1.70;1.69.0;1.69;1.68.0;1.68;1.67.0;1.67;1.6
6.0;1.66"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1492 ] Boost_USE_MULTITHREADED = "ON"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1493 ] Boost_USE_STATIC_LIBS = "YES"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1494 ] Boost_USE_STATIC_RUNTIME = <unset>
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1495 ] Boost_ADDITIONAL_VERSIONS = "1.66.0;1.66;1.73"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1496 ] Boost_NO_SYSTEM_PATHS = <unset>
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1528 ] BOOST_ROOT = <unset>
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1529 ] ENV{BOOST_ROOT} = "/usr/include/boost"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1530 ] BOOST_INCLUDEDIR = "/usr/include/boost"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1531 ] ENV{BOOST_INCLUDEDIR} = "/usr/include/boost"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1532 ] BOOST_LIBRARYDIR = "/usr/lib/x86_64-linux-gnu"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1533 ] ENV{BOOST_LIBRARYDIR} = "/usr/lib/x86_64-linux-gnu"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1605 ] _boost_INCLUDE_SEARCH_DIRS = "/usr/include/boost;/usr/include/boost/include;/usr/include/boost;PATHS;C:/boost/include;C:/boost;/
sw/local/include"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1606 ] _boost_PATH_SUFFIXES = "boost-1_66_0;boost_1_66_0;boost/boost-1_66_0;boost/boost_1_66_0;boost-1_66;boost_1_66;boost/boost-1_66;b
oost/boost_1_66;boost-1_73;boost_1_73;boost/boost-1_73;boost/boost_1_73;boost-1_73_0;boost_1_73_0;boost/boost-1_73_0;boost/boost_1_73_0;boost-1_73;boost_1_73;boost/boost-1_73;boost/boost_1_73;boost
-1_72_0;boost_1_72_0;boost/boost-1_72_0;boost/boost_1_72_0;boost-1_72;boost_1_72;boost/boost-1_72;boost/boost_1_72;boost-1_71_0;boost_1_71_0;boost/boost-1_71_0;boost/boost_1_71_0;boost-1_71;boost_1
_71;boost/boost-1_71;boost/boost_1_71;boost-1_70_0;boost_1_70_0;boost/boost-1_70_0;boost/boost_1_70_0;boost-1_70;boost_1_70;boost/boost-1_70;boost/boost_1_70;boost-1_69_0;boost_1_69_0;boost/boost-1_69_0;boost/boost_1_69_0;boost-1_69;boost_1_69;boost/boost-1_69;boost/boost_1_69;boost-1_68_0;boost_1_68_0;boost/boost-1_68_0;boost/boost_1_68_0;boost-1_68;boost_1_68;boost/boost-1_68;boost/boost_1_68;boost-1_67_0;boost_1_67_0;boost/boost-1_67_0;boost/boost_1_67_0;boost-1_67;boost_1_67;boost/boost-1_67;boost/boost_1_67;boost-1_66_0;boost_1_66_0;boost/boost-1_66_0;boost/boost_1_66_0;boost-1_66;boost_1_66;boost/boost-1_66;boost/boost_1_66"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1621 ] location of version.hpp: /usr/include/boost/version.hpp
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1661 ] Boost_VERSION = "1.73.0"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1662 ] Boost_VERSION_STRING = "1.73.0"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1663 ] Boost_VERSION_MACRO = "107300"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1664 ] Boost_VERSION_MAJOR = "1"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1665 ] Boost_VERSION_MINOR = "73"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1666 ] Boost_VERSION_PATCH = "0"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1667 ] Boost_VERSION_COUNT = "3"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1691 ] Boost_LIB_PREFIX = ""
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1692 ] Boost_NAMESPACE = "boost"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:801 ] _boost_COMPILER = "-gcc9" (guessed)
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1728 ] _boost_MULTITHREADED = "-mt"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1805 ] _boost_ARCHITECTURE_TAG = "" (detected)
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1809 ] _boost_RELEASE_ABI_TAG = "-"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1810 ] _boost_DEBUG_ABI_TAG = "-d"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1870 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "/usr/lib/x86_64-linux-gnu;/usr/include/boost/lib;/usr/include/boost/stage/lib;/usr/include/lib;/usr/include/../lib;/usr/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:1871 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "/usr/lib/x86_64-linux-gnu;/usr/include/boost/lib;/usr/include/boost/stage/lib;/usr/include/lib;/usr/include/../lib;/usr/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:2056 ] Searching for PROGRAM_OPTIONS_LIBRARY_RELEASE: boost_program_options-gcc9-mt-1_73;boost_program_options-gcc9-mt;boost_program_op
tions-gcc9-mt;boost_program_options-mt-1_73;boost_program_options-mt;boost_program_options-mt;boost_program_options-mt;boost_program_options
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:2111 ] Searching for PROGRAM_OPTIONS_LIBRARY_DEBUG: boost_program_options-gcc9-mt-d-1_73;boost_program_options-gcc9-mt-d;boost_program_
options-gcc9-mt-d;boost_program_options-mt-d-1_73;boost_program_options-mt-d;boost_program_options-mt-d;boost_program_options-mt;boost_program_options
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:2056 ] Searching for REGEX_LIBRARY_RELEASE: boost_regex-gcc9-mt-1_73;boost_regex-gcc9-mt;boost_regex-gcc9-mt;boost_regex-mt-1_73;boost_
regex-mt;boost_regex-mt;boost_regex-mt;boost_regex
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:2111 ] Searching for REGEX_LIBRARY_DEBUG: boost_regex-gcc9-mt-d-1_73;boost_regex-gcc9-mt-d;boost_regex-gcc9-mt-d;boost_regex-mt-d-1_73;
boost_regex-mt-d;boost_regex-mt-d;boost_regex-mt;boost_regex
-- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:2056 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-gcc9-mt-1_73;boost_filesystem-gcc9-mt;boost_filesystem-gcc9-mt;boost_
filesystem-mt-1_73;boost_filesystem-mt;boost_filesystem-mt;boost_filesystem-mt;boost_filesystem -- [ /snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:2111 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-gcc9-mt-d-1_73;boost_filesystem-gcc9-mt-d;boost_filesystem-gcc9-mt-d;boost_filesystem-mt-d-1_73;boost_filesystem-mt-d;boost_filesystem-mt-d;boost_filesystem-mt;boost_filesystem CMake Error at /snap/cmake/513/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
Could NOT find Boost (missing: program_options regex filesystem) (found
suitable version "1.73.0", minimum required is "1.66")
Call Stack (most recent call first):
/snap/cmake/513/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
/snap/cmake/513/share/cmake-3.18/Modules/FindBoost.cmake:2177 (find_package_handle_standard_args)
CMakeLists.txt:15 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred!
See also "/projects/myproj/model/CMakeFiles/CMakeOutput.log".
> rm^Crf CMakeFiles CMakeCache.txt
> vim CMakeLists.txt
> cmake --version
cmake version 3.18.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
有人能看一下并看看是否发现了什么吗?
答案1
现在我觉得自己很蠢。刚发完这个问题就发现了:
FIND_PACKAGE(Boost 1.66 COMPONENTS program_options regex filesystem REQUIRED)
需要包含版本 1.73