CMake FindBoost for -mt -s库后缀

时间:2013-05-05 04:57:38

标签: boost 64-bit cmake flags nmake

首先要做的事:Windows 7 x64使用带有CMake的Microsoft CL.exe命令行编译器,在amd64 Visual Studio命令行上正确配置。我已经解决了一些基本问题(例如,我试图链接到共享而不是静态Boost,我试图用x64目标链接x86 Boost等)现在我已经把它们直接解决了,我是试图将我的脑袋包裹在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 libs链接并停止尝试链接-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.

1 个答案:

答案 0 :(得分:2)

在Windows上,如果你已经构建了两个版本,那么就没有办法告诉CMake只能找到Boost的Release版本。在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_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这一事实让我觉得这可能会降低自动提升功能。当然使用set(Boost_USE_STATIC_RUNTIME ON)行,CMake甚至不应该寻找libboost_system-vc100-mt-gd-1_53.lib。

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

add_definitions(-DBOOST_ALL_NO_LIB)