简体   繁体   English

使用Boost的CMake找不到静态库

[英]CMake with Boost could not find static libraries

I have some troubles with CMake and Boost library. 我在使用CMake和Boost库时遇到了一些麻烦。 I have the following error : 我有以下错误:

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. 我在我的CMakeLists.txt中做了我在互联网上找到的所有内容,但它不起作用,我不明白。 I'm using Windows 8 with Visual Studio 12 and Boost is installed in the default directory. 我正在使用Windows 8和Visual Studio 12,并且Boost安装在默认目录中。 (C:/local/boost_1_55_0) (C:/本地/ 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 谢谢

I guess your compiled libraries is not in your BOOST_ROOT/lib/ folder. 我猜你的编译库不在你的BOOST_ROOT / lib /文件夹中。 In this case, you need to set your lib folder directory path. 在这种情况下,您需要设置lib文件夹目录路径。

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

or 要么

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

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

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.cmake file and solved my problem! FindBoost.cmake文件中解决了我的问题!

Putting these two lines in the Findboost.cmake solves the problem. 将这两行放在Findboost.cmake可以解决问题。 I am on windows 10 using visual studio 17 . 我在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。

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. 例如,如果你的Boost是64位且CMake的生成器设置为Win32(在Windows上是默认的),它将无法找到库。 This is set whenever you first try to configure the project and you can reset it by deleting the cache. 只要您第一次尝试配置项目时就会设置此项,您可以通过删除缓存来重置它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM