簡體   English   中英

FindPackageHandleStandardArgs.cmake 錯誤:137(消息):找不到 Boost(缺少:正則表達式)(找到合適的版本“1.72.0”,

[英]CMake Error at FindPackageHandleStandardArgs.cmake:137 (message): Could NOT find Boost (missing: regex) (found suitable version "1.72.0",

我從官方網站下載了 boost_1_72_0.tar.gz 並將其解壓縮到我的下載文件夾中/USERS/macuser/Downloads/boost_1_72_0

嘗試將簡單的 .cpp 文件與 Boost::regex 鏈接時,我不斷收到以下錯誤

-- The C compiler identification is AppleClang 11.0.0.11000033
-- The CXX compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning at /usr/local/Cellar/cmake/3.15.4/share/cmake/Modules/FindBoost.cmake:1144 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.15.4/share/cmake/Modules/FindBoost.cmake:1266 (_Boost_COMPONENT_DEPENDENCIES)
  /usr/local/Cellar/cmake/3.15.4/share/cmake/Modules/FindBoost.cmake:1904 (_Boost_MISSING_DEPENDENCIES)
  examples/HelloBoost/CMakeLists.txt:27 (find_package)


CMake Error at /usr/local/Cellar/cmake/3.15.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find Boost (missing: regex) (found suitable version "1.72.0",
  minimum required is "1.72.0")
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.15.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/Cellar/cmake/3.15.4/share/cmake/Modules/FindBoost.cmake:2161 (find_package_handle_standard_args)
  examples/HelloBoost/CMakeLists.txt:27 (find_package)

我的 CMakeLists.txt 文件如下所示:

cmake_minimum_required(VERSION 3.1)

set (CMAKE_CXX_STANDARD 11)
set (PROJECT "Hello-Boost")

# headers
include_directories(include)

# sources
file(GLOB SOURCES "src/*.cpp")


# BOOST Configuration

set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

set(Boost_INCLUDE_DIR /USERS/macuser/Downloads/boost_1_72_0/boost)
set(Boost_LIBRARY_DIR /USERS/macuser/Downloads/boost_1_72_0/libs)

find_package(Boost 1.72.0 COMPONENTS regex REQUIRED)

if(Boost_FOUND)
    message("boost lib: ${Boost_LIBRARIES}")
    message("boost inc:${Boost_INCLUDE_DIR}")
emdif()

include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

# executable target
add_executable(${PROJECT} ${SOURCES})

# link boost
target_link_libraries(${PROJECT} PUBLIC Boost::regex)

我的問題很簡單:
以上帝的名義,Cmake 出了什么問題? 為什么地球上數以百萬計的其他人已經成功地找到了該死的 boost 庫?

謝謝

在使用Boost::regex之前,您需要構建 Boost,因為它不是一個只有頭文件的庫(與大多數其他 Boost 庫一樣)。 這通常在安裝過程中通過 homebrew 或 macports 等包管理器完成。

無需將僅標頭庫添加到find_package調用的COMPONENTS部分。

然后你做一個

find_package(BOOST 1.72.0 COMPONENTS regex REQUIRED)

就像您已經做的那樣,然后通過以下方式將庫添加到您的目標中

target_link_libraries(${PROJECT} PUBLIC Boost::regex)

如果您打算稍后使用其他 Boost 庫(僅標頭或不使用標頭),則應在 target_link_libraries 調用中明確命名它們或添加

target_link_libraries(${PROJECT} PUBLIC ${Boost_LIBRARIES})

這也會將 Boost 目錄添加到您的包含目錄中。 然后您可以省略以下幾行

include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

如果您想使用靜態庫而不是動態庫,請使用

set(Boost_USE_STATIC_LIBS ON) 

find_package調用之前。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM