在Visual Studio 2010中使用/clr进行Boost

Boost in Visual Studio 2010 using /clr

本文关键字:clr 进行 Boost Visual Studio 2010      更新时间:2023-10-16

我创建了一系列类,我希望将它们合并到Visual Studio 2010的Windows Forms应用程序中。这些类使用 Boost,特别是 boost::thread。

启用公共语言运行库支持后,我收到以下错误消息:

1>c:program files (x86)boostboost_1_47boostthreadwin32thread_primitives.hpp(314): error C2472: 'boost::detail::win32::interlocked_bit_test_and_set' cannot be generated in managed code: 'Found an intrinsic not supported in managed code'; compile with /clr to generate a mixed image
1>c:program files (x86)boostboost_1_47boostthreadwin32basic_timed_mutex.hpp(160): error C2472: 'boost::detail::basic_timed_mutex::unlock' cannot be generated in managed code: 'Found an intrinsic not supported in managed code'; compile with /clr to generate a mixed image

我明白消息在说什么,但我不知道如何解决它。在项目属性中禁用公共语言运行时支持会产生大量其他错误,因此:如何将/clr 合并到我正在使用的 Boost 库中?

Boost.thread 使用一些线程本地存储调用,如果直接将它们与 CLR 代码链接,则这些调用不起作用。 在VS2008中,链接会成功,但你会在启动时崩溃 - 我怀疑这是VS2010风格的相同问题的症状。 解决方法是将 boost.thread 构建为 DLL 而不是静态链接它,也许它会以这种方式为您链接......