0

我对 boost 和 .net-Framework 有疑问。我在没有.net 的情况下编写了我的课程。该项目运行良好,现在我将类文件包含到 Windows 窗体应用程序中。发生了许多编译器错误,例如“__declspec(dllexport) 无法与 /clr:pure 或 /clr:safe 一起使用”在 singleton.hpp(boost-library)中。我创建一个例子。在 Form1-header 中,仅包含此类,没有其他任何操作,仅来自 Visual Studio 2010 生成的代码。

这是一个测试类,我创建它是为了向您展示一个简单的案例:

#ifndef FOO_H
#define FOO_H

#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>

class Foo
{
private:
    int  name;

public:
    void setName(int name);
    int getName(void);
private:
    friend boost::serialization::access;
    template<class Archive>
    void serialize (Archive& arch, const unsigned int)
    {
        arch & BOOST_SERIALIZATION_NVP(this->name);
    }
};
#endif

我尝试将 /clr:pure 切换到 /clr,这样编译器可以编译它,但是在启动程序时发生了错误。它的标题是“调试断言失败!” 在 exe 文件中。在消息框中,您还可以阅读“Expression:_CrtIsValidHeapPointer(pUserData)” 目前我使用 boost 1.52.0,但我也尝试使用 boost 1.53.0。我用“bootstrap.bat”和“bjam.exe”安装了boost。

有人知道这个问题的解决方案吗?

4

1 回答 1

0

好的,Hans Passant 找到了解决方案。我为一些有同样问题但不知道如何更改/clr 的人发布了方法。您必须将 /clr:pure 更改为 /clr。发生的错误只是暂时的。现在它起作用了。

要在 Visual Studio (2010/2012) 中获得 /clr:pure,您必须进入项目选项卡并单击属性。单击 C/C++>>General,然后将“公共语言运行时支持”从 /clr:pure 到 /clr。

于 2013-03-29T23:37:56.850 回答