2016-02-16 55 views
1

我已經在Visual Studio 2015年一個簡單的項目,以重現我在較廣的代碼庫與升壓1.60連接錯誤建築fibonnacci用的boost :: coroutine2與升壓1.60例如使用動態鏈接

我有一個問題試圖簡單地編譯和運行在這裏找到的示例:https://github.com/boostorg/coroutine2/blob/develop/example/fibonacci.cpp 有1個輕微變化 - 使用動態庫。

因此,我的全部代碼如下:

#include <cstdlib> 
#include <iostream> 

#define BOOST_ALL_DYN_LINK //This is the only difference 

#include <boost/coroutine2/all.hpp> 

int main() { 
    boost::coroutines2::coroutine<int>::pull_type source(
     [](boost::coroutines2::coroutine<int>::push_type & sink) { 
     int first = 1, second = 1; 
     sink(first); 
     sink(second); 
     for (int i = 0; i < 8; ++i) { 
      int third = first + second; 
      first = second; 
      second = third; 
      sink(third); 
     } 
    }); 
    for (auto i : source) { 
     std::cout << i << " "; 
    } 
    std::cout << "\nDone" << std::endl; 
    return EXIT_SUCCESS; 
} 

但是,我得到一個鏈接錯誤:

1>------ Build started: Project: coroutine2-test, Configuration: Debug Win32 ------ 
1> Source.cpp 
1>c:\users\lynden\boost_1_60_0\boost\context\execution_context.ipp(209): warning C4251: 'boost::context::execution_context::ptr_': class 'boost::intrusive_ptr<boost::context::detail::activation_record>' needs to have dll-interface to be used by clients of class 'boost::context::execution_context' 
1>Source.obj : error LNK2001: unresolved external symbol "public: static class boost::intrusive_ptr<struct boost::context::detail::activation_record> boost::context::detail::activation_record::current_rec" ([email protected][email protected]@[email protected]@@[email protected][email protected]@[email protected]@@@[email protected]) 
1>D:\random projects\coroutine2-test\Debug\coroutine2-test.exe : fatal error LNK1120: 1 unresolved externals 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

我當然有設置包括目錄到我的升壓目錄和我鏈接器附加目錄到boost/stage/lib目錄。

+0

coroutine2與協同程序不同,但是您讓我意識到我沒有boost_coroutine2-vc140-mt-gd-1_60.lib或.dll - 我在想這是必要的還是僅用於標題? 我對這種方法的理解是通過一些VS hax來自動鏈接它們,而不需要'-lboost_coroutine2'部分。 –

+0

我能夠然而,隨着靜態鏈接建立這個例子,我更大的代碼庫,我們使用動態鏈接,所以我想我還需要這與動態鏈接 –

回答

0

你需要對boost.context鏈接(使用boost.coroutine2)。 告訴編譯器/鏈接器它可以在哪裏找到boost.context的共享庫。

+0

我確實鏈接到共享庫正常工作: .. 。LINK.EXE/ERRORREPORT:PROMPT/OUT: 「d:\隨機項目\ coroutine2測試\調試\ coroutine2-TEST.EXE」/增量/ NOLOGO/LIBPATH:C:\用戶\林登\ boost_1_60_0 \階段\ lib中KERNEL32的.lib USER32.LIB GDI32.LIB winspool.lib comdlg32.lib advapi32.lib SHELL32.LIB ole32.lib oleaut32.lib UUID.LIB odbc32.lib odbccp32.lib ** 「boost_coroutine-vc140-MT-GD-1_60.lib」 「boost_context-vc140-mt-gd-1_60.lib」「boost_system-vc140-mt-gd-1_60.lib」** ...等 –

-1

您需要使用標準C++ 14(選項「-std = C++ 14」)編譯Boost,否則Boost.Context將不會提供必要的實現來支持Boost.Coroutine2,編譯器將無法鏈接。

+0

Visual Studio是否提供這樣的選項? –

+0

根據他們的網站,VS Studio不完全支持C++ 14功能。 [鏈接](https://msdn.microsoft.com/en-us/library/hh567368.aspx#cpp14table) 我不知道是否有可能編譯完整的C++ 14的支持推動作用。 您應該檢查Boost文檔關於建立它VS [鏈接](http://www.boost.org/doc/libs/1_60_0/more/getting_started/windows.html#get-boost) 如果是類似作爲構建Linux的提升,你可能需要添加到CXXFLAGS選項「-std = C++ 14」(我不知道msvc是否支持該選項)。 – Claymore