我已經在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目錄。
coroutine2與協同程序不同,但是您讓我意識到我沒有boost_coroutine2-vc140-mt-gd-1_60.lib或.dll - 我在想這是必要的還是僅用於標題? 我對這種方法的理解是通過一些VS hax來自動鏈接它們,而不需要'-lboost_coroutine2'部分。 –
我能夠然而,隨着靜態鏈接建立這個例子,我更大的代碼庫,我們使用動態鏈接,所以我想我還需要這與動態鏈接 –