【问题标题】:CMake with Boost could not find static libraries带有 Boost 的 CMake 找不到静态库
【发布时间】:2014-01-06 10:38:19
【问题描述】:

我在使用 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!

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

这是我的 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})

有人可以帮帮我吗?

谢谢

【问题讨论】:

  • 你能在你的 Cmake 脚本中使用 message() 打印出 Boost_LIBRARYDIR 和 Boost_INCLUDE_DIR 的值吗?
  • 如果您要在 CMakeLists.txt 中添加路径,我会使用 / 而不是 \
  • 向我们展示你用来安装 boost 的命令。对我来说,我通常使用“./b2 install”
  • @DinoStray 我不使用命令来“安装”,除了 apt/dnf/etc。

标签: c++ windows boost makefile cmake


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    我也有同样的问题

    通过命令解决

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

    【讨论】:

      【解决方案3】:

      我在带有 vs2017 的 Windows 10 上,我只是添加:

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

      之前

          "unset(_boost_RELEASE_NAMES)" 
      

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

      【讨论】:

        【解决方案4】:

        将这两行放在Findboost.cmake 中可以解决问题。 我在windows 10 使用visual studio 17

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

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

        【讨论】:

          【解决方案5】:

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

          【讨论】:

            猜你喜欢
            • 2012-08-14
            • 1970-01-01
            • 2020-05-24
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-12-26
            • 1970-01-01
            相关资源
            最近更新 更多