gpt4 book ai didi

c++ - 使用 CMake 查找使用 CLang 编译的 Boost

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:35:18 25 4
gpt4 key购买 nike

我已经使用 rubenvb 在 Windows 上编译了 Boost 1.51.0|的 CLang 构建。我实际上使用 MinGW 编译了 b2:

bootstrap mingw
... compiling b2 using mingw...

然后我用 CLang 编译了这些库:

b2 toolset=clang stage --stagedir=. --build-type=complete --with-regex ...

顺便说一句,即使我指定了 --build-type=complete lib 目录中也没有 DLL,但我在某处读到 CLang 在 Windows 上的链接仍然存在问题,所以这可能是原因。无论如何,静态库对我来说很好。我在 %BOOST_ROOT%\lib 中得到了这些文件:

libboost_regex-clang31-1_51.lib
libboost_regex-clang31-d-1_51.lib
libboost_regex-clang31-mt-1_51.lib
libboost_regex-clang31-mt-d-1_51.lib
libboost_regex-clang31-mt-s-1_51.lib
libboost_regex-clang31-mt-sd-1_51.lib
libboost_regex-clang31-s-1_51.lib
libboost_regex-clang31-sd-1_51.lib

现在,如果我从命令行用 CLang 编译一些东西,一切正常。当我尝试让 CMake 查找 Boost 库时出现问题:它根本找不到它们。我尝试使用此 CMakeFiles.txt:

cmake_minimum_required (VERSION 2.8)
project(ccc)

# Setting/unsetting this does not change anything.
set(Boost_USE_STATIC_LIBS ON)

find_package(Boost COMPONENTS regex REQUIRED)

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

add_executable(ccc main.cpp)

target_link_libraries(ccc
${Boost_REGEX_LIBRARY}
)

使用 MinGW(和 MinGW 编译版本的 Boost)构建它,它可以工作。如果我尝试使用 CLang(在设置了 CC=clangCXX=clang++BOOST_ROOT=C:/misc/boost/clang-1_51_0 之后) 它不会:

D:\Desktop\ppp>cmake -G "MinGW Makefiles" ..\ccc
-- The C compiler identification is Clang 3.1.0
-- The CXX compiler identification is Clang 3.1.0
-- Check for working C compiler: C:/misc/clang/bin/clang.exe
-- Check for working C compiler: C:/misc/clang/bin/clang.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/misc/clang/bin/clang++.exe
-- Check for working CXX compiler: C:/misc/clang/bin/clang++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at C:/misc/cmake/share/cmake-2.8/Modules/FindBoost.cmake:1191 (message):
Unable to find the requested Boost libraries.

Boost version: 1.51.0

Boost include path: C:/misc/boost/clang-1_51_0

The following Boost libraries could not be found:

boost_regex

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.
Call Stack (most recent call first):
CMakeLists.txt:5 (find_package)


CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Boost_REGEX_LIBRARY (ADVANCED)
linked by target "ccc" in directory D:/Desktop/ccc

-- Configuring incomplete, errors occurred!

但是,如果我手动编译它又可以工作了:

clang++ main.cpp -I%BOOST_ROOT% -L%BOOST_ROOT%\lib -llibboost_regex-clang31-1_51
...Ok, and the executable works

手动设置 BOOST_LIBRARYDIR 也不起作用。使用反斜杠 \ 也不行。

最佳答案

查看文件“C:/misc/cmake/share/cmake-2.8/Modules/FindBoost.cmake”,您可以找到与您可以使用的 Boost 相关的所有变量的列表。您需要的是 Boost_COMPILER(Boost_DETAILED_FAILURE_MSG 也可用于诊断问题):

#   Boost_COMPILER               Set this to the compiler suffix used by Boost
# (e.g. "-gcc43") if FindBoost has problems finding
# the proper Boost installation

关于c++ - 使用 CMake 查找使用 CLang 编译的 Boost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12715294/

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