2015-03-05 18 views
7

My CMakeFiles.txt trông như thế này:Liên kết tăng viện với Boost_USE_STATIC_LIB OFF trên Windows

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() 

tôi làm dự án cho Visual Studio 2013 64-bit:

cmake -G "Visual Studio 12 Win64" -DBOOST_LIBRARYDIR=D:\Development\Tools\boost_1_57_0\stage\x64\lib ..\KServer 

Đầu ra là:

-- 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 

Tất cả đều tốt và tốt.

Vấn đề bắt đầu ở đây:

Khi tôi thay đổi tập tin cmake tôi để sử dụng:

set(Boost_USE_STATIC_LIBS OFF) 

Sau đó tôi nhận được lỗi sau trong Visual Studio khi tòa nhà:

error LNK1104: cannot open file 'libboost_filesystem-vc120-mt-gd-1_57.lib' D:\Development\Private\C++\KServerProject\src\LINK foo 

Kiểm tra số Property Pages trong studio, thư viện được thêm dưới dạng phụ thuộc:

enter image description here

Khi tay thêm thư mục D:\Development\Tools\boost_1_57_0\stage\x64\lib-Additional Library Directories nó xây dựng tốt.

Tôi làm cách nào để tạo dự án bằng cách sử dụng lib động?

+0

Trong bản dựng tăng cường mà tôi sử dụng với cmake, tôi có 3 thư mục trong thư mục gốc của bản dựng. xây dựng, bao gồm và lib. Mặc dù tôi xây dựng từ nguồn. – drescherjm

+0

Tôi sử dụng kiểu dựng sẵn sau đây với bjam '--build-type = complete stage install' – drescherjm

+0

Nó không phải là một vấn đề với tăng. Tôi đã xây dựng với 'hoàn thành'. Tôi cần dự án sử dụng boost để làm việc với liên kết động khi tạo bằng cmake. – Asken

Trả lời

12

Tôi tin rằng bạn cần phải thêm

add_definitions(-DBOOST_ALL_NO_LIB) 

Xem http://www.boost.org/doc/libs/1_57_0/libs/config/doc/html/index.html. Tôi có nó đặt trong CMakeLists.txt của tôi và nó hoạt động cho studio trực quan của tôi xây dựng với tăng. Là một thử nghiệm, tôi đã xóa nó và nhận được lỗi tương tự như bạn đã làm.

Đối với những gì đáng giá, dưới đây là cách tôi sử dụng boost với cmake.

# 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() 
+0

WOW! hoạt động rất tốt ......! Tôi không cần 'BOOST_ALL_DYN_LINK' trong trường hợp của tôi: https://github.com/lumenitb/vpercnode –

Các vấn đề liên quan