编译器警告C4251:导出* .dll中的类时出错

时间:2011-04-12 10:54:07

标签: c++ dll dllexport kinect

编辑:原谅我的noobish-ness,我以前从未实现过包装.dll! :S

我一直在修补一些最近发布的Kinect Sensor黑客攻击(即OpenKinectOpenNI),我现在正试图将功能包装在* .dll中以供使用在我希望写的各种“测试”程序中。

到目前为止,我已经设置了一个* .dll项目,并且已经有很多库功能,但是我在整个地方都收到了C4251编译器警告。

在项目设置中,我已经静态链接了OpenNI.lib文件,到目前为止我的库标题看起来像这样:

#ifdef LIBKINECT_EXPORTS
#define LIBKINECT_API __declspec(dllexport)
#else
#define LIBKINECT_API __declspec(dllimport)
#endif

// This class is exported from the LibKinect.dll
class LIBKINECT_API CLibKinect
{
public:

    CLibKinect(void);
    ~CLibKinect(void);

    bool Init(void);

protected:

private:

    xn::Context                     m_xContext;
    xn::DepthGenerator              m_xDepthGen;
};

我的stdafx.h文件包含:

#pragma once

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>

#include <XnOpenNI.h>
#include <XnCodecIDs.h>
#include <XnCppWrapper.h>

现在我尝试创建一个Windows控制台应用程序来测试库,我收到很多error C2653: 'xn' : is not a class or namespace name错误。我希望在应用程序中我只需要包含并链接到包装器* .dll也不是所有的OpenNI内容,以便隐藏底层实现,这是不正确的?

1 个答案:

答案 0 :(得分:1)

由于您希望隐藏在实现中使用xn命名空间的事实,因此不应将其放在库头文件中。解决此问题的最简单方法是使用pimpl idiom

相关问题