[英]Visual Studio 2017, “Mixing a dll boost library with a static runtime”, when linking python_boost.lib
[英]Linking boost library with Boost_USE_STATIC_LIB OFF on Windows
我的CMakeFiles.txt看起來像這樣:
cmake_minimum_required ( VERSION 2.6 )
# Set warnings on and enable debugging
SET( CMAKE_C_FLAGS "-Wall -q" )
include(FindBoost)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package( Boost 1.57.0 COMPONENTS system filesystem REQUIRED )
if( Boost_FOUND )
message( STATUS "Boost found!" )
include_directories(${Boost_INCLUDE_DIRS})
add_executable(foo main.cpp)
# Needed for asio
if(WIN32)
target_link_libraries(foo wsock32 ws2_32)
endif()
target_link_libraries(foo ${Boost_LIBRARIES})
endif()
我為Visual Studio 2013 64位渲染項目:
cmake -G "Visual Studio 12 Win64" -DBOOST_LIBRARYDIR=D:\Development\Tools\boost_1_57_0\stage\x64\lib ..\KServer
輸出是:
-- The C compiler identification is MSVC 18.0.31101.0
-- The CXX compiler identification is MSVC 18.0.31101.0
-- Check for working C compiler using: Visual Studio 12 2013 Win64
-- Check for working C compiler using: Visual Studio 12 2013 Win64 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64
-- Check for working CXX compiler using: Visual Studio 12 2013 Win64 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.57.0
-- Boost version: 1.57.0
-- Found the following Boost libraries:
-- system
-- filesystem
-- Boost found!
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Development/Private/C++/KServerProject
這一切都很好,很好。
問題從這里開始:
當我更改我的cmake文件使用時:
set(Boost_USE_STATIC_LIBS OFF)
然后,我在構建時在Visual Studio中收到以下錯誤:
error LNK1104: cannot open file 'libboost_filesystem-vc120-mt-gd-1_57.lib' D:\Development\Private\C++\KServerProject\src\LINK foo
檢查工作室中的Property Pages
,庫將作為依賴項添加:
手動將文件夾D:\\Development\\Tools\\boost_1_57_0\\stage\\x64\\lib
到Additional Library Directories
它可以正常構建。
如何使用動態庫創建項目?
我相信你需要補充一下
add_definitions( -DBOOST_ALL_NO_LIB )
請參閱http://www.boost.org/doc/libs/1_57_0/libs/config/doc/html/index.html 。 我把它設置在我的CMakeLists.txt中,它適用於我的視覺工作室構建與增強。 作為測試,我刪除它並得到你做的同樣的錯誤。
對於它的價值,這里是我如何使用cmake的boost。
# boost
set(Boost_NO_SYSTEM_PATHS true)
set (Boost_USE_STATIC_LIBS OFF CACHE BOOL "use static libraries from Boost")
set (Boost_USE_MULTITHREADED ON)
find_package(Boost REQUIRED
COMPONENTS
system program_options thread filesystem
date_time chrono timer regex serialization
)
include_directories(${Boost_INCLUDE_DIRS})
link_libraries(${Boost_LIBRARIES})
if (WIN32)
# disable autolinking in boost
add_definitions( -DBOOST_ALL_NO_LIB )
# force all boost libraries to dynamic link (we already disabled
# autolinking, so I don't know why we need this, but we do!)
add_definitions( -DBOOST_ALL_DYN_LINK )
endif()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.