C++ 带有 Boost 的 CMake 找不到静态库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20654959/
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-08-27 23:16:16  来源:igfitidea点击:

CMake with Boost could not find static libraries

c++windowsboostmakefilecmake

提问by Nonouf

I have some troubles with CMake and Boost library. I have the following error :

我在使用 CMake 和 Boost 库时遇到了一些麻烦。我有以下错误:

CMake Error at C:/Program Files (x86)/CMake
2.8/share/cmake-2.8/Modules/FindBoost.cmake:1111 (message):   Unable to find the requested Boost libraries.

  Boost version: 1.55.0

  Boost include path: C:/local/boost_1_55_0

  Could not find the following static Boost libraries:

          boost_system
          boost_date_time
          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:10 (find_package)


-- Configuring incomplete, errors occurred!

I did everything I found to internet in my CMakeLists.txt but it's not working, I don't understand. I'm using Windows 8 with Visual Studio 12 and Boost is installed in the default directory. (C:/local/boost_1_55_0)

我在我的 CMakeLists.txt 中做了我在互联网上找到的所有事情,但它不起作用,我不明白。我将 Windows 8 与 Visual Studio 12 一起使用,并且 Boost 安装在默认目录中。(C:/local/boost_1_55_0)

Here my CMakeLists.txt :

这是我的 CMakeLists.txt :

cmake_minimum_required(VERSION 2.6)

project (server)

set(BOOST_ROOT "c:\local\boost_1_55_0")

set (Boost_USE_STATIC_LIBS ON) set (Boost_MULTITHREADED ON) set
(Boost_USE_STATIC_RUNTIME OFF)

find_package(Boost 1.55 COMPONENTS system date_time regex REQUIRED)
add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS})

set(SRCS main.cpp Server.cpp Client.cpp)

set(HEADERS Server.h Client.h)

include_directories(${Boost_INCLUDE_DIR})

add_executable(babel_server ${SRCS} ${HEADERS})

target_link_libraries(babel_server ${Boost_LIBRARIES})

Anyone can help me please ?

任何人都可以帮助我吗?

Thanks

谢谢

回答by kwanti

I guess your compiled libraries is not in your BOOST_ROOT/lib/ folder. In this case, you need to set your lib folder directory path.

我猜你编译的库不在你的 BOOST_ROOT/lib/ 文件夹中。在这种情况下,您需要设置 lib 文件夹目录路径。

set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib/)

or

或者

set(BOOST_LIBRARYDIR path/to/your/lib/folder)

回答by CLIFFORD P Y

I have same problem

我有同样的问题

solved by using command

使用命令解决

bjam install --prefix="<your boost install folder>" --with-system --with-date_time --with-random link=static runtime-link=shared threading=multi

回答by chen kailin

I am on windows 10 with vs2017 ,I just add :

我在使用 vs2017 的 Windows 10 上,我只是添加:

    "set(Boost_LIB_PREFIX "lib")
    set(_boost_RELEASE_ABI_TAG ".lib")"

before

    "unset(_boost_RELEASE_NAMES)" 

in FindBoost.cmakefile and solved my problem!

FindBoost.cmake文件中并解决了我的问题!

回答by Salah Eddine Ghamri

Putting these two lines in the Findboost.cmakesolves the problem. I am on windows 10using visual studio 17.

把这两行放在里面就Findboost.cmake解决了问题。我正在windows 10使用visual studio 17.

    set(Boost_LIB_PREFIX "lib")

    set(_boost_RELEASE_ABI_TAG ".lib")

If i am correct, FindBoost was searching for files without .lib but the libraries have .lib in the end.

如果我是对的,FindBoost 正在搜索没有 .lib 的文件,但库最后有 .lib 。

回答by tapix

Make sure you've selected the right platform for the generator.
For example if your Boost is 64-bit and CMake's generator is set to Win32 (default on Windows), it will not be able to find the libraries. This is set whenever you first try to configure the project and you can reset it by deleting the cache.

确保您为发电机选择了正确的平台。
例如,如果您的 Boost 是 64 位并且 CMake 的生成器设置为 Win32(Windows 上的默认设置),它将无法找到库。每当您第一次尝试配置项目时都会设置它,您可以通过删除缓存来重置它。