c++ - boost.future 导致 clr 出现问题

标签 c++ visual-studio-2012 boost clr

我将 visual studio 2012 与需要链接到 native 库的 clr 库一起使用。 我的图书馆正在使用 boost::future。

我在对托管项目使用 future::then(F &&) 函数时遇到了这个问题:

Error   910 error LNK2022: metadata operation failed (8013119F) : A TypeRef exists which        should, but does not, have a corresponding TypeDef: (dummy): (0x0100003e).  D:\ClrProject\somefile.obj

按照其他问题的建议,我尝试使库中的 dummy 类型完整,因为我无法从模板内部转发声明嵌套结构,而 可以做到boost::thread::dummy 结构。

这并没有解决问题。

我的设置如下:

  • boost 1.55。
  • 使用 boost .dll。
  • 定义 BOOST_RESULT_OF_USE_DECLTYPE
  • 定义 BOOST_THREAD_PROVIDES_FUTURE
  • 定义 BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION

我也在依赖的 .dll 上使用这些非常定义,以确保 API 的所有部分都正确公开。

最佳答案

已解决。

@Hans Passant 你的建议是对的。我只是没有以正确的方式放置 #pragma

我必须放置编译指示,以便将我的 header 编译为非托管代码。完成后,我的代码的模板实例化似乎是作为非托管发出的。到那时,问题就消失了。

所以我做的是这样的:

#pragma managed(push, off)
#include "MyHeaderWithFutures.h"
#pragma managed(pop)

void f() {
   //
   f = myObject.Something().then(...);
}

关于c++ - boost.future 导致 clr 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25241983/

相关文章:

c++ - Boost 异常导致堆栈指针损坏(运行时检查失败 #0 ...)

c++ - 错误调用函数 : "argument of type "int"is incompatible with parameter of type "int *"

c++ - 使用 VS 宏设置 PreprocessorDefinitions

c# - 如何将资源嵌入到 appx 包中?

c++ - C 接口(interface)作为带有 Boost 后端的 API

c++ - Boost:我们如何为 TCP 服务器指定 "any port"?

c++ - 如何判断当前进程是否已经锁定了一个文件?

c++ - 有没有办法忽略 hg blame 中的提交?

c++ - boost::interprocess::file_lock 与 std::ostream 一起使用时的错误行为

c++ - 在无法正常工作的单个窗口上显示多个图像(C++ VS12)