2015-03-05 3 views
7

Meine CMakeFiles.txt wie folgt aussieht:Linking-Boost-Bibliothek mit Boost_USE_STATIC_LIB OFF auf 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() 

ich das Projekt für Visual Studio 2013 64-Bit-Render:

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

Die Ausgabe lautet:

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

Das ist alles gut und gut.

Problem beginnt hier:

Wenn ich meine cmake-Datei zu verwenden ändern:

set(Boost_USE_STATIC_LIBS OFF) 

ich dann erhält die folgenden Fehler in Visual Studio, wenn Gebäude:

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

Checking Die Property Pages im Studio die Bibliothek wird als Abhängigkeit hinzugefügt:

enter image description here

Wenn manuell den Ordner Hinzufügen D:\Development\Tools\boost_1_57_0\stage\x64\lib-Additional Library Directories es baut in Ordnung.

Wie bekomme ich es, um ein Projekt mit dynamischen Bibliotheken zu erstellen?

+0

In meinem Boost-Build, den ich mit cmake verwende, habe ich 3 Ordner im Stammverzeichnis des Builds. Build, Include und Lib. Obwohl ich aus der Quelle baue. – drescherjm

+0

Ich verwende den folgenden Build-Typ mit bjam '--build-type = complete stage install' – drescherjm

+0

Es ist kein Problem mit Boost. Ich habe mit 'complete' gebaut. Ich brauche das Projekt mit Boost, um mit Dynamic Linking zu arbeiten, wenn mit cmake erzeugt wird. – Asken

Antwort

12

Ich glaube, Sie

add_definitions(-DBOOST_ALL_NO_LIB) 

Siehe http://www.boost.org/doc/libs/1_57_0/libs/config/doc/html/index.html hinzufügen müssen. Ich habe es in meiner CMakeLists.txt eingestellt und es funktioniert für meine Visual Studio Builds mit Boost. Als Test habe ich es entfernt und habe den gleichen Fehler wie du gemacht.

Für was es wert ist, hier ist, wie ich Boost mit cmake verwenden.

# 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! das funktioniert so gut ......! Ich brauche in meinem Fall nicht "BOOST_ALL_DYN_LINK": https://github.com/lumenitb/vpercnode –