关于C ++:Cmake无法找到Boost库
boostc++cmake
Cmake cannot find Boost libraries
我是Cmake的新手,并增强了C ++中的库。 我正在做一个需要boost和Cmake的项目。 我正在使用Cmake版本2.8.11,MS Visual Studio 2013和Boost 1.54.0。 当我尝试从Cmake配置时,出现以下错误:
CMake Error at C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1106 (message):
Unable to find the requested Boost libraries.Boost version: 1.54.0Boost include path: D:/boost_1_54_0The following Boost libraries could not be found:boost_threadboost_systemboost_logboost_log_setupboost_program_optionsNo 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:20 (find_package)
我已经看到很多与我有关的问题并尝试过,但都徒劳无功。 我的Cmakelists.txt文件如下所示:
################################
Boost
################################
ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
ADD_DEFINITIONS(-DBoost_USE_STATIC_LIBS=ON)
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON)
set(Boost_INCLUDE_DIR D:/boost_1_54_0)
set(Boost_LIBRARY_DIR D:/boost_1_54_0/stage/lib)
find_package( Boost 1.54.0 REQUIRED thread system log log_setup program_options)
find_package( Threads )
INCLUDE_DIRECTORIES( B o o s t I N C L U D E D I R ) L I N K D I R E C T O R I E S ( {Boost_INCLUDE_DIR} ) LINK_DIRECTORIES( BoostINCLUDEDIR)LINKDIRECTORIES({Boost_LIBRARY_DIR})
将Boost_DEBUG设置为ON之后的CMake输出如下:
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:476 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:478 ] Boost_USE_MULTITHREADED = TRUE
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:480 ] Boost_USE_STATIC_LIBS = TRUE
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:482 ] Boost_USE_STATIC_RUNTIME =
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:484 ] Boost_ADDITIONAL_VERSIONS =
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:486 ] Boost_NO_SYSTEM_PATHS =
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:538 ] Declared as CMake or Environmental Variables:
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:540 ] BOOST_ROOT = D:/boost_1_54_0
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:542 ] BOOST_INCLUDEDIR =
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:544 ] BOOST_LIBRARYDIR =
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:546 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:615 ] Include debugging info:
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:617 ] _boost_INCLUDE_SEARCH_DIRS = D:/boost_1_54_0/include;D:/boost_1_54_0;PATHS;C:/boost/include;C:/boost;/sw/local/include
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:619 ] _boost_PATH_SUFFIXES = boost-1_56_0;boost_1_56_0;boost/boost-1_56_0;boost/boost_1_56_0;boost-1_56;boost_1_56;boost/boost-1_56;boost/boost_1_56;boost-1_55_0;boost_1_55_0;boost/boost-1_55_0;boost/boost_1_55_0;boost-1_55;boost_1_55;boost/boost-1_55;boost/boost_1_55;boost-1_54_0;boost_1_54_0;boost/boost-1_54_0;boost/boost_1_54_0;boost-1_54;boost_1_54;boost/boost-1_54;boost/boost_1_54
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:639 ] location of version.hpp: D:/boost_1_54_0/boost/version.hpp
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:663 ] version.hpp reveals boost 1.54.0
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:739 ] guessed _boost_COMPILER = -vc120
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:749 ] _boost_MULTITHREADED = -mt
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:792 ] _boost_RELEASE_ABI_TAG = -
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:794 ] _boost_DEBUG_ABI_TAG = -gd
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:842 ] _boost_LIBRARY_SEARCH_DIRS = D:/boost_1_54_0/lib;D:/boost_1_54_0/stage/lib;D:/boost_1_54_0/lib;D:/boost_1_54_0/../lib;D:/boost_1_54_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for THREAD_LIBRARY_RELEASE: libboost_thread-vc120-mt-1_54;libboost_thread-vc120-mt;libboost_thread-mt-1_54;libboost_thread-mt;libboost_thread;libboost_thread-vc120-mt-s-1_54;libboost_thread-vc120-mt-s;libboost_thread-mt-s-1_54;libboost_thread-mt-s
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for THREAD_LIBRARY_DEBUG: libboost_thread-vc120-mt-gd-1_54;libboost_thread-vc120-mt-gd;libboost_thread-mt-gd-1_54;libboost_thread-mt-gd;libboost_thread-mt;libboost_thread;libboost_thread-vc120-mt-s-gd-1_54;libboost_thread-vc120-mt-s-gd;libboost_thread-mt-s-gd-1_54;libboost_thread-mt-s-gd
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for SYSTEM_LIBRARY_RELEASE: libboost_system-vc120-mt-1_54;libboost_system-vc120-mt;libboost_system-mt-1_54;libboost_system-mt;libboost_system;libboost_system-vc120-mt-s-1_54;libboost_system-vc120-mt-s;libboost_system-mt-s-1_54;libboost_system-mt-s
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for SYSTEM_LIBRARY_DEBUG: libboost_system-vc120-mt-gd-1_54;libboost_system-vc120-mt-gd;libboost_system-mt-gd-1_54;libboost_system-mt-gd;libboost_system-mt;libboost_system;libboost_system-vc120-mt-s-gd-1_54;libboost_system-vc120-mt-s-gd;libboost_system-mt-s-gd-1_54;libboost_system-mt-s-gd
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for LOG_LIBRARY_RELEASE: libboost_log-vc120-mt-1_54;libboost_log-vc120-mt;libboost_log-mt-1_54;libboost_log-mt;libboost_log;libboost_log-vc120-mt-s-1_54;libboost_log-vc120-mt-s;libboost_log-mt-s-1_54;libboost_log-mt-s
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for LOG_LIBRARY_DEBUG: libboost_log-vc120-mt-gd-1_54;libboost_log-vc120-mt-gd;libboost_log-mt-gd-1_54;libboost_log-mt-gd;libboost_log-mt;libboost_log;libboost_log-vc120-mt-s-gd-1_54;libboost_log-vc120-mt-s-gd;libboost_log-mt-s-gd-1_54;libboost_log-mt-s-gd
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for LOG_SETUP_LIBRARY_RELEASE: libboost_log_setup-vc120-mt-1_54;libboost_log_setup-vc120-mt;libboost_log_setup-mt-1_54;libboost_log_setup-mt;libboost_log_setup;libboost_log_setup-vc120-mt-s-1_54;libboost_log_setup-vc120-mt-s;libboost_log_setup-mt-s-1_54;libboost_log_setup-mt-s
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for LOG_SETUP_LIBRARY_DEBUG: libboost_log_setup-vc120-mt-gd-1_54;libboost_log_setup-vc120-mt-gd;libboost_log_setup-mt-gd-1_54;libboost_log_setup-mt-gd;libboost_log_setup-mt;libboost_log_setup;libboost_log_setup-vc120-mt-s-gd-1_54;libboost_log_setup-vc120-mt-s-gd;libboost_log_setup-mt-s-gd-1_54;libboost_log_setup-mt-s-gd
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for PROGRAM_OPTIONS_LIBRARY_RELEASE: libboost_program_options-vc120-mt-1_54;libboost_program_options-vc120-mt;libboost_program_options-mt-1_54;libboost_program_options-mt;libboost_program_options;libboost_program_options-vc120-mt-s-1_54;libboost_program_options-vc120-mt-s;libboost_program_options-mt-s-1_54;libboost_program_options-mt-s
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for PROGRAM_OPTIONS_LIBRARY_DEBUG: libboost_program_options-vc120-mt-gd-1_54;libboost_program_options-vc120-mt-gd;libboost_program_options-mt-gd-1_54;libboost_program_options-mt-gd;libboost_program_options-mt;libboost_program_options;libboost_program_options-vc120-mt-s-gd-1_54;libboost_program_options-vc120-mt-s-gd;libboost_program_options-mt-s-gd-1_54;libboost_program_options-mt-s-gd
[ C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1017 ] Boost_FOUND = 1
CMake Error at C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1106 (message):
Unable to find the requested Boost libraries.Boost version: 1.54.0Boost include path: D:/boost_1_54_0The following Boost libraries could not be found:boost_threadboost_systemboost_logboost_log_setupboost_program_optionsNo 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:26 (find_package)
我也尝试写set(Boost_USE_STATIC_LIBS ON),但是不幸的是,它没有帮助。 欢迎提出建议。 谢谢。
相关讨论
是的,在调用CMakeLists.txt文件中的find_package之前,已使用set(BOOST_ROOT D:boost_1_54_0)对其进行了设置,但出现相同的错误。
如果将set(Boost_DEBUG ON)添加到CMakeLists.txt,则重新运行时应该会得到更多的调试输出。 如果在此之后您仍然有错误,可以将CMake输出粘贴到您的问题中以供我们查看吗?
您是如何建立Boost 1.54.0的?
@Vertexwahn:我是从MS Visual Studio命令提示符构建的,方法是先从boost所在的目录内部执行bootstrap命令,然后再使用bjam命令。
@Fraser:我将Boost_DEBUG设置为ON并再次尝试,但是仍然存在相同的错误。 我已经在问题中添加了CMake输出。
@ user1382494-不错。 现在,您需要查看boost文件夹并找到实际的库。 根据CMake告诉您的使用值检查其路径和名称。 那么,例如,boost线程库的完整路径是什么?
您的配置看起来有些奇怪和肮脏。特别是像这样的东西:
1
ADD_DEFINITIONS(-DBoost_USE_STATIC_LIBS=ON)
这不是C / C ++预处理程序定义!这是一个CMake变量,用于控制CMake如何定义带有Boost库的项目的链接阶段。
如果您正确编译了Boost并没有弄乱任何东西,则目录结构通常如下所示:
<boost-dir>includeboostaccumulators...aligned_storage.hpp...liblibboost_atomic-mt-s.a...
注意:
在您的情况下,Boost的根目录似乎是D:/boost_1_54_0。
如果您的情况不像上面那样,那么我建议您手动将其重新排列为上面的一个,因为这又应该是这样。
完成后,让我们进行一些CMake配置。我建议首先保持简单和整洁,并遵守CMake约定。测试以下内容:
set(BOOST_INCLUDEDIR D:/boost_1_54_0/include)
set(BOOST_LIBRARYDIR D:/boost_1_54_0/lib)
注意:您可以在FindBoost.cmake的顶部找到对这两个变量的完整描述。
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
注意:这是通过正确设置CMake变量来强制执行静态链接的方法,但与通过设置不存在的C / C ++预处理程序定义所执行的操作不同。
find_package(Boost
1.54.0
COMPONENTS thread
system
log
log_setup
program_options
REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(<target_name> ${Boost_LIBRARIES})
注意:代替,输入要构建的目标的名称(可执行文件,静态/共享库等)。
相关讨论
由于Op是在VS下构建的,因此他的库文件可能最终以stage而不是lib结尾。话虽这么说,在CMake中设置除BOOST_ROOT之外的任何内容已经或多或少地带来了麻烦。
@ComicSansMS:是的。但是我给了他一个建议,告诉他如何测试他的装置是否应该正常工作。在CMakeLists.txt中显式设置路径确实违反了一般建议,并且一旦作者确认至少对他有效,我会丢下一条注释并使用更好的选项来编辑我的答案。顺便说一句,即使设置BOOST_ROOT也是不好的做法。所有这些路径提示变量都应在CMake调用期间进行设置,因为它们仅取决于当前环境。
@Haroogan:非常感谢您的详细答复。目前,我不得不格式化我的机器,并且由于一些任务而面临一些麻烦。修复该问题后,我将立即恢复。再次感谢您的耐心配合。
@Haroogan:我清理了我的CmakeLists.txt文件,并按照您的建议执行了步骤。但是,仍然存在相同的错误。我,然后卸载了MS Visual Studio 2013,安装了MS Visual Studio 2012,然后再次尝试。错误仍然存??在。然后,我在Ubuntu中安装了Boost 1.54.0和Cmake,并且在Ubuntu中运行良好。因此,我现在正在Ubuntu中进行处理以节省时间。
您是否尝试过set(BOOST_LIBRARYDIR D:boost_1_54_0lib)和set(BOOST_LIBRARYDIR D:boost_1_54_0libstage)?此外,我看到您正在使用VS 2013,调试显示CMake不在搜索*-vc130-库,它仅在搜索-vc120-*。这很可能就是原因。您是否有适用于VS 12或VS 13的Boost库?
是的,我尝试了两种方法。是的,VS 13存在很多问题,因此我也尝试使用VS 12,但没有任何变化。不过,在Ubuntu中,现在一切都正常。
就我而言,有两个问题阻止了构建。目录结构很奇怪,我没有在cmakelists.txt中指定set(Boost_USE_STATIC_LIBS ON)。
如果不应用某些修补程序,则无法使用VS2013构建Boost 1.54.0。另请参见此处如何使用新的Visual Studio 2013预览版构建增强功能?
如果构建正确,则其他所有功能均应正常工作。
在lib文件夹中,重命名:
libboost_thread-vc100-mt-1_49.lib至boost_thread-vc100-mt-1_49.lib
libboost_thread-vc100-mt-gd-1_49.lib至boost_thread-vc100-mt-gd-1_49.lib
… 等等。然后可以找到它们。