链接器错误构建 fibonnacci 示例与 boost::coroutine2 与 Boost 1.60 使用动态链接
Linker error building fibonnacci example with boost::coroutine2 with Boost 1.60 using Dynamic Linking
我在Visual Studio 2015中做了一个简单的项目,以重现我在Boost 1.60的较大代码库中遇到的问题
我尝试简单地编译并运行此处找到的示例:https://github.com/boostorg/coroutine2/blob/develop/example/fibonacci.cpp略有变化 - 使用动态库。
因此,我的完整代码如下:
#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:userslyndenboost_1_60_0boostcontextexecution_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" (?current_rec@activation_record@detail@context@boost@@2V?$intrusive_ptr@Uactivation_record@detail@context@boost@@@4@A)
1>D:random projectscoroutine2-testDebugcoroutine2-test.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我当然将包含目录设置为我的提升目录,将链接器附加目录设置为提升/阶段/库目录。
你需要链接到boost.context(由boost.coroutine2使用(。告诉编译器/链接器在哪里可以找到boost.context的共享库。
你需要
使用标准的C++14(选项"-std=c++14"(编译Boost,否则Boost.Context将无法提供必要的实现来支持Boost.Coroutine2,编译器将无法链接。
相关文章:
- 在Cygwin上链接Boost库
- CMAKE中无法链接Boost
- 使用cmake错误链接boost日志
- 如何在 Oracle Linux 上的 Eclipse 中编译和链接 boost 库
- 链接 boost 库时"Error while loading shared libraries"引发的,除了我无法使用 root 访问权限来修复它
- 跨多个环境动态链接 Boost
- 无法通过 CMake 链接 Boost 1.63.0
- 静态链接再次链接boost.test和cmake在Windows上的mingw
- 链接boost.python示例的问题
- 在CLion中链接Boost.Asio时Static_initialization_and_distruction错误
- HelloWorld:使用CMake下载、构建和链接Boost
- 链接Boost线程库
- 使用CMake问题链接Boost(Ubuntu 14.04)
- Ubuntu - 链接 boost.python - 致命错误:找不到 pyconfig
- 尝试链接 boost::文件系统以调试 MSVC11 项目时出现链接器错误
- 在OSX 10.10上链接Boost Python
- 在 Eclipse(或 Xcode)中链接 Boost 程序选项
- 链接boost线程库时发生gcc 4.8链接器错误
- 在CLion中使用CMake静态链接boost库
- 无法使用mingw32g++链接boost