使用CMake查找用CLang编译的Boost
Finding Boost compiled with CLang with CMake
我在Windows上使用ruenvb的CLang构建编译了Boost 1.51.0。实际上,我使用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=clang
、CXX=clang++
和BOOST_ROOT=C:/misc/boost/clang-1_51_0
之后),它不会:
D:Desktopppp>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
相关文章:
- 编译 Boost 时在 OS X 上的"ld:未知选项:-soname"
- 用STD = C 11或其他标准编译Boost,例如Ash C 14
- 编译Boost ASIO示例时出现错误
- 使用Cygwin win32_api.hpp编译Boost Log中的错误
- 无法编译 boost::asio::basic_datagram_socket<boost::asio::ip::udp>::basic_datagram_socket()
- 编译boost.spirit.karma示例,customize_embedded_container.cpp失败
- 在 solaris cc v5.8 上编译 Boost
- 在Windows上使用zlib编译boost 1.62 / 1.63
- 错误编译Boost.log
- 试图编译Boost和openSSL时(使用WebSocket 或CPPRESTSDK)进行编译错误
- 在Windows上编译Boost :: ASIO示例
- 我可以编译boost.python模块而没有BJAM
- 在spirit parser Action中,在上下文参数上编译boost :: bind(成员函数)上的错误
- 在 Linux 上编译 boost asio 时出现链接错误
- 在目标平台上编译 Boost 自己是否有意义
- 编译 Boost.Bind时出错
- 在OS X上使用clang编译boost regex时发生链接错误
- 编译boost时"threading=multi"究竟做了什么
- 编译 boost 文件系统的教程文件时遇到问题
- 从Linux到Windows交叉编译boost 1.57的问题