找到使用CMake与CLang编译的Boost

Cla*_*dio 6 c++ boost cmake clang

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

bootstrap mingw
... compiling b2 using mingw...
Run Code Online (Sandbox Code Playgroud)

然后我用CLang编译了库:

b2 toolset=clang stage --stagedir=. --build-type=complete --with-regex ...
Run Code Online (Sandbox Code Playgroud)

顺便说一句,即使我指定--build-type=completelib目录中没有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
Run Code Online (Sandbox Code Playgroud)

现在,如果我从命令行编译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}
    )
Run Code Online (Sandbox Code Playgroud)

使用MinGW(和Boost的MinGW编译版本)构建它可以工作.如果我铿锵尝试(有设置好的后CC=clang,CXX=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!
Run Code Online (Sandbox Code Playgroud)

但是,如果我手动编译它再次工作:

clang++ main.cpp -I%BOOST_ROOT% -L%BOOST_ROOT%\lib -llibboost_regex-clang31-1_51
...Ok, and the executable works
Run Code Online (Sandbox Code Playgroud)

手动设置BOOST_LIBRARYDIR也不起作用.也没有使用反斜杠\.

小智 5

查看文件"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
Run Code Online (Sandbox Code Playgroud)