【问题标题】:CMake FindBoost for -mt-s library suffixCMake FindBoost for -mt-s 库后缀
【发布时间】:2013-05-05 04:57:38
【问题描述】:

第一件事:Windows 7 x64 使用 Microsoft CL.exe 命令行编译器和 CMake,在 amd64 Visual Studio 命令行上正确配置。我已经解决了一些基本问题(例如,我试图链接共享而不是静态 Boost,我试图链接 x86 Boost 与 x64 目标等),现在我已经弄清楚了,我试图将我的头脑围绕在 Boost 的 CMake 标志上。

我知道 Boost 的不同命名法(例如 -mt-gd 的含义。)我的 Boost 库都是 -mt-s(发布多线程)。

我想知道 FindBoost 的哪个 CMake 变量对应于 -g 和 -d 后缀。

这是我的 CMakeLists:

cmake_minimum_required( VERSION 2.8 )

project( echoserv )

set( APP_NAME Echoserv )
set( MAIN_SOURCE echoserv.cpp )
set( CMAKE_BUILD_TYPE "RELEASE" )

set( Boost_USE_STATIC_RUNTIME ON )
set( Boost_USE_STATIC_LIBS ON )
set( Boost_DEBUG ON )

find_package( Boost COMPONENTS system REQUIRED )

add_executable( ${APP_NAME} ${MAIN_SOURCE} )

include_directories( ${Boost_INCLUDE_DIR} )
link_directories( ${Boost_LIBRARY_DIRS} )
target_link_libraries( ${APP_NAME} ${Boost_LIBRARIES} )

我尝试编译时产生的错误是:

LINK : fatal error LNK1104: cannot open file 'libboost_system-vc100-mt-gd-1_53.lib'

这是因为我的 Boost 库都是“-vc100-mt-s-1_53.lib”形式的。那么我应该使用什么标志来让它与 -mt-s 库链接并停止尝试链接到 -mt-gd?

资源:

http://www.boost.org/doc/libs/1_53_0/more/getting_started/windows.html#library-naming http://www.cmake.org/cmake/help/v2.8.8/cmake.html#module%3aFindBoost

显然 cmake.org 链接应该有用,但我认为我正确设置了变量,它仍在尝试链接 mt-gd。

编辑:这里是设置 Boost_DEBUG ON 的输出:

(请注意,Boost 库已安装到 %LIB%。)

E:\fastmeta\dev\workspace\personal\learncpp\socks\echoserv>nmake

Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:566 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:568 ] Boost_USE_MULTITHREADED = TRUE
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:570 ] Boost_USE_STATIC_LIBS = ON
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:572 ] Boost_USE_STATIC_RUNTIME = ON
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:574 ] Boost_ADDITIONAL_VERSIONS =
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:576 ] Boost_NO_SYSTEM_PATHS =
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:644 ] Declared as CMake or Environmental Variables:
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:646 ]   BOOST_ROOT =
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:648 ]   BOOST_INCLUDEDIR =
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:650 ]   BOOST_LIBRARYDIR =
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:652 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:734 ] location of version.hpp: C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include/boost/version.hpp
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:754 ] version.hpp reveals boost 1.53.0
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:786 ] guessed _boost_COMPILER = -vc100
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:796 ] _boost_MULTITHREADED = -mt
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:839 ] _boost_RELEASE_ABI_TAG = -s
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:841 ] _boost_DEBUG_ABI_TAG = -sgd
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:884 ] _boost_LIBRARY_SEARCH_DIRS = C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include/lib;C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include/../lib;C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include/stage/lib;C:/boost/lib;C:/boost;C:\Program Files (x86)/boost/boost_1_53_0/lib;C:\Program Files (x86)/boost/boost_1_53/lib;C:\Program Files (x86)/boost/lib;C:\Program Files (x86)/boost;/sw/local/lib
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:962 ] Searching for SYSTEM_LIBRARY_RELEASE: libboost_system-vc100-mt-s-1_53;libboost_system-vc100-mt-s;libboost_system-mt-s-1_53;libboost_system-mt-s;libboost_system
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:994 ] Searching for SYSTEM_LIBRARY_DEBUG: libboost_system-vc100-mt-sgd-1_53;libboost_system-vc100-mt-sgd;libboost_system-mt-sgd-1_53;libboost_system-mt-sgd;libboost_system-mt;libboost_system
-- [ E:/fastmeta/dev/tools/cmake/CMake 2.8/share/cmake-2.8/Modules/FindBoost.cmake:1108 ] Boost_FOUND = TRUE
-- Boost version: 1.53.0
-- Found the following Boost libraries:
--   system
-- Configuring done
-- Generating done
-- Build files have been written to: E:/fastmeta/dev/workspace/personal/learncpp/socks/echoserv
Linking CXX executable Echoserv.exe
LINK : fatal error LNK1104: cannot open file 'libboost_system-vc100-mt-1_53.lib'

LINK failed. with 2
NMAKE : fatal error U1077: '"E:\fastmeta\dev\tools\cmake\CMake 2.8\bin\cmake.exe
"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
Stop.

【问题讨论】:

  • 如果我的回答没有帮助,您可以在更改为set(Boost_DEBUG ON)后添加您的CMake命令的输出吗?
  • 添加了调试输出。请注意,Boost 库安装在 %LIB% amd64 目录中。
  • 在重新运行 CMake 之前,您已经删除了 CMakeCache.txt?

标签: boost 64-bit cmake flags nmake


【解决方案1】:

在 Windows 上,没有办法告诉 CMake 只查找 Boost 的发布版本(如果您同时构建了这两个版本)。而在 Windows 上,如果您打算在 Debug 和 Release 中构建项目,您通常也会构建 Boost 的 Debug 和 Release 版本,因为它们每个都链接到不同版本的 C 运行时库;即通常你不仅有 libboost_system-vc100-mt-s-1_53.lib,还有 libboost_system-vc100-mt-sgd-1_53.lib 在同一个文件夹中。

所以对于你现在的 CMakeLists.txt(假设正确找到了 boost 根目录),${Boost_LIBRARIES} 的值应该类似于:

optimized;<path to boost root>/stage/lib/libboost_system-vc100-mt-s-1_53.lib;debug;<path to boost root>/stage/lib/libboost_system-vc100-mt-sgd-1_53.lib

然后,当您执行 target_link_libraries( ${APP_NAME} ${Boost_LIBRARIES} ) 时,您是在说要链接哪个版本的 boost lib,具体取决于它是 Debug 还是 Release 构建。

VS 正在寻找 libboost_system-vc100-mt-gd-1_53.lib 的事实让我认为这可能是由于 boost 的自动链接功能。当然,对于 set(Boost_USE_STATIC_RUNTIME ON) 行,CMake 甚至不应该寻找 libboost_system-vc100-mt-gd-1_53.lib。

您可以通过添加以下行来关闭 Boost 的自动链接功能:

add_definitions(-DBOOST_ALL_NO_LIB)

【讨论】:

  • 您好弗雷泽,感谢您的回复。我只构建了发布版本。你如何告诉它只链接到 Release?
  • 如果您只提供了发布版本的 Boost 库,那么 ${Boost_LIBRARIES} 将只包含那些(没有任何 optimized 或 debug 参数),无论您是在 Debug 或 Release 中构建。
  • 您是否确定使用/MT 标志集(即使用静态CRT)而不是/MD 来编译您的程序?如果你有这样的不匹配(boost 用/MT 编译,而你的用/MD 编译)并且你没有add_definitions(-DBOOST_ALL_NO_LIB),那么你会收到类似于你看到的一个。但我也希望它包含更多关于原因的信息。
猜你喜欢
  • 1970-01-01
  • 2011-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多