Jav*_*ock 5 boost cmake visual-studio-2012
我正在尝试为Visual Studio 2012生成一些我需要的Boost 1.58库(chrono,regex和thread),并将这些库与CMake链接起来.我有真正的问题让CMake和Visual Studio找到或链接libs,具体取决于我设置的配置.
我终于使用以下配置:
bjam.exe --link = static --threading multi --variant = debug stage
但这似乎不会生成静态库.
我应该如何生成库并使用CMake搜索它们,以便Visual Studio正确链接它们?
我终于提出了解决方案,我认为它足够详细,可以成为一个通用的答案.
Visual Studio搜索动态库,因此我们需要将Boost库编译为共享,多线程,调试和发布以及运行时链接共享.在使用bjam.exe的windows中,除链接外,所有命令都有前缀" - ",因此构建库的正确方法是:
bjam.exe link=shared --threading=multi --variant=debug --variant=release --with-chrono --with-regex --with-thread stage
Run Code Online (Sandbox Code Playgroud)
这将生成文件夹Boost/stage/lib中的libs和DLL,因此我们需要设置一个环境变量Boost_LIBRARY_DIR C:/ Boost/stage/lib.
还有更多选择可供参考:
runtime-link = shared/static
toolset= msvc-11.0
Run Code Online (Sandbox Code Playgroud)
这些库将有一个这样的名称用于发布:
boost_chrono-vc110-mt-1_58.lib
boost_chrono-vc110-mt-1_58.dll
Run Code Online (Sandbox Code Playgroud)
并进行调试:
boost_chrono-vc110-mt-gd-1_58.lib
boost_chrono-vc110-mt-gd-1_58.dll
Run Code Online (Sandbox Code Playgroud)
为了让CMake正确链接它们,我们需要在CMakeLists.txt中编写以下内容:
add_definitions( -DBOOST_ALL_DYN_LINK ) //If not VS will give linking errors of redefinitions
set(Boost_USE_STATIC_LIBS OFF )
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost COMPONENTS thread chrono regex REQUIRED )
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES( ${PROJ_NAME} ${Boost_LIBRARIES} )
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3734 次 |
| 最近记录: |