c++ - 使用动态链接在 Boost 1.60 中使用 boost::coroutine2 构建 fibonnacci 示例的链接器错误

标签 c++ boost visual-studio-2015 boost-coroutine2

我在 visual studio 2015 中做了一个简单的项目来重现我在使用 Boost 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" (?current_rec@activation_record@detail@context@boost@@2V?$intrusive_ptr@Uactivation_record@detail@context@boost@@@4@A)
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 目录,并将我的链接器附加目录设置为 boost/stage/lib 目录。

最佳答案

您需要链接到 boost.context(由 boost.coroutine2 使用)。 告诉编译器/链接器在哪里也可以找到 boost.context 的共享库。

关于c++ - 使用动态链接在 Boost 1.60 中使用 boost::coroutine2 构建 fibonnacci 示例的链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35427622/

相关文章:

swift - 在 Cocoa 应用程序中打开 App Sandbox 时未在套接字上接收任何 UDP 数据

visual-studio-2015 - Visual Studio 未部署到 iOS 模拟器

visual-studio-2015 - .NET 4.5.2 编译的应用程序需要 .NET 4.6

c++ - 在 C++ vs2015 中嵌入 python 3

c++ - 一个人应该在堆栈上分配的最大数量

c++ - 使用 boost::spirit 时无法转换 boost::variant 中的 boost::fusion 结构

c++ - 如何使用 boost 升级互斥体扩展 C++ boost 列表容器以实现线程安全实现?

c++ - boost::asio::deadline_timer 绑定(bind)到多态套接字类指针

c++ - 队列结构给出了奇怪的错误

c++ - QFileDialog 不发出信号