windows CMake 找不到 Boost 库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8077652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:55:14  来源:igfitidea点击:

CMake doesn't find Boost libraries

windowsboostcmake

提问by JonathanK

I'm trying to use a CMake script to compile a Boost-based application on Windows. The header-only libraries work fine, but CMake fails to find the libraries (the following Boost libraries could not be found: boost_serialization). The relevant part of the CMake script is:

我正在尝试使用 CMake 脚本在 Windows 上编译基于 Boost 的应用程序。仅头文件库工作正常,但 CMake 无法找到这些库(无法找到以下 Boost 库:)boost_serialization。CMake 脚本的相关部分是:

# Path where CMake can find additional libraries
SET(CMAKE_PREFIX_PATH Libs)

# Boost
SET(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0")
SET(Boost_USE_STATIC_LIBS   ON)
find_package(Boost REQUIRED COMPONENTS serialization)

I have a folder called "Libs" inside my project where third-party libraries such as DevIL and Boost are stored, so I set this first. It works fine for Devil and Boost header-only stuff, so I assume I should not need the BOOST_ROOT variable. The Boost installation is the standard source distribution from boost.org which I compiled with BJam. The libraries are stored in boost_1_47_0\bin.v2\libs, and I didn't change anything in the build process.

我的项目中有一个名为“Libs”的文件夹,其中存储了 DevIL 和 Boost 等第三方库,因此我先设置了它。它适用于 Devil 和 Boost 头文件,所以我认为我不需要 BOOST_ROOT 变量。Boost 安装是来自 boost.org 的标准源发行版,我用BJam编译。库存储在 中boost_1_47_0\bin.v2\libs,我在构建过程中没有更改任何内容。

I think it is a bit odd, that the boost_1_47_0\libsfolder doesn't contain any library files but BJam files and other stuff, but that shouldn't be a problem since this seems to be the normal way to build Boost on Windows from the source.

我认为这有点奇怪,该boost_1_47_0\libs文件夹不包含任何库文件,但包含 BJam 文件和其他内容,但这应该不是问题,因为这似乎是从源代码在 Windows 上构建 Boost 的正常方法。

I looked at the Debug output from the FindBoost.cmakefile (I'm using the default script from CMake 2.8) and it doesn't seem to look into bin.v2. Instead it searches boost_ROOT/lib, but when I copied the content from bin.v2\libsto lib it still didn't find anything.

我查看了FindBoost.cmake文件中的 Debug 输出(我使用的是 CMake 2.8 中的默认脚本),但它似乎没有查看bin.v2. 相反,它搜索boost_ROOT/lib,但是当我将内容从bin.v2\libslib复制到 lib 时,它仍然没有找到任何东西。

So what is an elegant way to find Boost that will also work on other platforms with common Boost distributions?

那么找到 Boost 的优雅方法是什么,它也可以在具有常见 Boost 发行版的其他平台上运行?

采纳答案by JonathanK

Well, I solved the problem, but I'm not fully satisfied with my solution.

好吧,我解决了这个问题,但我对我的解决方案并不完全满意。

In my opinion the problem was that BJam creates a too complex folder structure. Now I just copied the library files from "boost_1_47_0\bin.v2\libs\serialization\build\msvc-9.0\debug\link-static\threading-multi" to "boost_1_47_0\lib".

在我看来,问题在于 BJam 创建了一个过于复杂的文件夹结构。现在我只是将库文件从“boost_1_47_0\bin.v2\libs\serialization\build\msvc-9.0\debug\link-static\threading-multi”复制到“boost_1_47_0\lib”。

I have to do this by hand, but I'm not using that many Boost libraries, so this step is OK in my opinion. I will document my solution aside the CMake script, so other users should get along with that.

我必须手动执行此操作,但我没有使用那么多 Boost 库,因此我认为这一步是可以的。我将在 CMake 脚本旁边记录我的解决方案,因此其他用户应该能够接受。

回答by drescherjm

I would try setting BOOST_ROOTinside your CMakeLists.txtfile. I know that CMake 2.8.6 will find Boost 1.47.0 when you set the Boost_ADDITIONAL_VERSIONSvariable since it works for me on Windows when I have BOOST_ROOTset.

我会尝试BOOST_ROOT在您的CMakeLists.txt文件中设置。我知道当您设置Boost_ADDITIONAL_VERSIONS变量时,CMake 2.8.6 会找到 Boost 1.47.0,因为它在我BOOST_ROOT设置后在 Windows 上对我有用。

Here is what I have in one project:

这是我在一个项目中的内容:

    set( BOOST_COMPONENTS_NEEDED serialization )

    # The following verifyies that BOOST_ROOT is set properly.
    if(NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")
        FILE( TO_CMAKE_PATH $ENV{BOOST_ROOT} BOOST_ROOT )
        if( NOT EXISTS ${BOOST_ROOT} )
            MESSAGE( STATUS  ${BOOST_ROOT} " does not exist. Checking if BOOST_ROOT was a quoted string.." )
            STRING( REPLACE "\"" "" BOOST_ROOT ${BOOST_ROOT} )
            if( EXISTS ${BOOST_ROOT} )
                MESSAGE( STATUS "After removing the quotes " ${BOOST_ROOT} " was now found by CMake" )
            endif( EXISTS ${BOOST_ROOT})
        endif( NOT EXISTS ${BOOST_ROOT} )

    # Save the BOOST_ROOT in the cache
        if( NOT EXISTS ${BOOST_ROOT} )
            MESSAGE( WARNING ${BOOST_ROOT} " does not exist." )
        else(NOT EXISTS ${BOOST_ROOT})
            SET (BOOST_ROOT ${BOOST_ROOT} CACHE STRING "Set the value of BOOST_ROOT to point to the root folder of your boost install." FORCE)
            #SET (BOOST_INCLUDEDIR ${BOOST_ROOT}/Include)
            #SET (BOOST_LIBRARYDIR ${BOOST_ROOT}/lib)
        endif( NOT EXISTS ${BOOST_ROOT} )

    endif(NOT BOOST_ROOT AND NOT $ENV{BOOST_ROOT} STREQUAL "")

    if( WIN32 AND NOT BOOST_ROOT )
        MESSAGE( WARNING "Please set the BOOST_ROOT environment variable." )
    endif( WIN32 AND NOT BOOST_ROOT )

    set(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0")
    set(Boost_DEBUG ON)
    set(Boost_USE_STATIC_LIBS       OFF)
    set(Boost_USE_MULTITHREADED      ON)
    set(Boost_USE_STATIC_RUNTIME    OFF)
    FIND_PACKAGE(Boost 1.47.0 COMPONENTS ${BOOST_COMPONENTS_NEEDED})
    if(Boost_FOUND)
        MESSAGE( STATUS "Setting up boost." )
        include_directories(${Boost_INCLUDE_DIRS})
        if(Boost_DEBUG)
            MESSAGE( STATUS "BOOST Libraries " ${Boost_LIBRARIES} )
            FOREACH(BOOST_COMPONENT ${BOOST_COMPONENTS_NEEDED})
                STRING( TOUPPER ${BOOST_COMPONENT} BOOST_COMPONENT_UPCASE )
                MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} ": " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY} )
                MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} " Debug: " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY_DEBUG} )
                MESSAGE( STATUS "Boost " ${BOOST_COMPONENT} " Release: " ${Boost_${BOOST_COMPONENT_UPCASE}_LIBRARY_RELEASE} )
            ENDFOREACH(BOOST_COMPONENT)
        endif(Boost_DEBUG)
    endif(Boost_FOUND)

回答by deft_code

I've had a problem with this before. For some reason b2 (aka BJam) created the Boost libraries with a leading "lib".

我以前遇到过这个问题。出于某种原因,b2(又名 BJam)创建了带有前导“lib”的 Boost 库。

The CMake script will not look for a file named libboost_thread.lib. It will only find boost_thread.lib. Remove the leading liband CMake should find them.

CMake 脚本不会查找名为libboost_thread.lib. 它只会找到boost_thread.lib. 删除前导lib,CMake 应该会找到它们。

回答by Chuck Claunch

I came here with a similar issue and just wanted to say my fix was similar, but not exactly the same.

我带着类似的问题来到这里,只是想说我的修复方法很相似,但并不完全相同。

My install prefix was C:\lib\boost\boost_1_57_0. I set a BOOST_ROOTenvironment variable pointing to that directory, but CMake (3.1.0) still couldn't find the headers. I realized the headers defaulted to install to C:\lib\boost\boost_1_57_0\include\boost-1_57\boost. I'm not going to run multiple versions so I just moved the final Boost directory down one and removed the boost-1_57directory and ended up with headers here:

我的安装前缀是C:\lib\boost\boost_1_57_0. 我设置了一个BOOST_ROOT指向该目录的环境变量,但 CMake (3.1.0) 仍然找不到标题。我意识到标头默认安装到C:\lib\boost\boost_1_57_0\include\boost-1_57\boost. 我不打算运行多个版本,所以我只是将最终的 Boost 目录下移一个并删除了该boost-1_57目录,最后得到了标题:

C:\lib\boost\boost_1_57_0\include\boost

And CMake found everything.

CMake 找到了一切。

回答by Dr. Frank Heimes

You can add the following option to the command line of CMake to tell CGAL to use the static Boost libraries:

您可以在 CMake 的命令行中添加以下选项来告诉 CGAL 使用静态 Boost 库:

-DCGAL_Boost_USE_STATIC_LIBS=true