【发布时间】:2013-12-13 20:24:32
【问题描述】:
我有以下 CMakeLists.txt 文件:
cmake_minimum_required(VERSION 2.6)
project (some_project)
set(BOOST_ROOT "E:/libs/boost_1_54_0")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
set (SOURCES
main.cpp)
add_executable (${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})
enable_testing ()
add_test (${PROJECT_NAME} ${PROJECT_NAME})
当我尝试将此文件与 CMake 一起使用时,出现以下错误:
cmake.exe .
-- Building for: Visual Studio 12
-- The C compiler identification is MSVC 18.0.21005.1
-- The CXX compiler identification is MSVC 18.0.21005.1
-- Check for working C compiler using: Visual Studio 12
-- Check for working C compiler using: Visual Studio 12 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 12
-- Check for working CXX compiler using: Visual Studio 12 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at e:/software/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1111 (message):
Unable to find the requested Boost libraries.
Boost version: 1.54.0
Boost include path: E:/libs/boost_1_54_0
Could not find the following static Boost libraries:
boost_unit_test_framework
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:8 (find_package)
-- Configuring incomplete, errors occurred!
在“e:\libs\boost_1_54_0\stage\lib\”目录中,我有以下 *.lib 文件:
libboost_unit_test_framework-vc110-mt-1_54.lib
libboost_unit_test_framework-vc110-mt-gd-1_54.lib
libboost_unit_test_framework-vc110-mt-s-1_54.lib
libboost_unit_test_framework-vc110-mt-sgd-1_54.lib
我做错了什么?
【问题讨论】:
-
仔细阅读 my other answer,尤其是它下面的所有 cmets,关于您的库适用于 VS 11,但您使用的是 VS 12 的事实。
-
@Haroogan 什么? msvc-11.0 是 Visual Studio 2012 的编译器
-
哦,我的错。我以为它在库中显示 VS 的版本,正确的是
vc110。好的,那么第一个奇怪的是Boost include path: E:/libs/boost_1_54_0。它应该是E:/libs/boost_1_54_0/include。此外,link_directories(${Boost_LIBRARY_DIR})是多余的,您最好使用Boost_INCLUDE_DIRS- 复数。 -
也运行
set(Boost_DEBUG ON),看看你得到了什么。 -
没有。如果您选择 Visual Studio 12 作为您的生成器,它适用于 Visual Studio 2013 而不是 Visual Studio 2012。2 位数年份和版本号不匹配。 Visual Studio 11 是 Visual Studio 2012 的正确生成器。