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

发布于 2024-10-31 21:57:49 字数 1301 浏览 0 评论 0原文

编辑:请原谅我的笨蛋,我以前从未实现过包装器 .dll! :S

我一直在修改一些最近发布的 Kinect 传感器 hack(即 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 内容,以便隐藏底层实现,这是不正确的吗?

EDIT: Forgive my noobish-ness, I haven't ever implemented a wrapper .dll before! :S

I've been tinkering a bit with some of the recently released Kinect Sensor hacks (namely OpenKinect and OpenNI) and I'm now trying to wrap the functionality in a *.dll for use in various "test" programs that I hope to write.

So far I've set up a *.dll project and have got a lot of the library functionality in, however I'm getting C4251 compiler warnings all over the place.

In the project settings I've got the OpenNI.lib file statically linked, so far my library header looks like this:

#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;
};

And my stdafx.h file contains:

#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>

Now I've attempted to create a windows console app to test the library and I get lots of error C2653: 'xn' : is not a class or namespace name errors. I was hoping that in the application I would only have to include and link to the wrapper *.dll not all of the OpenNI stuff as well, so as to hide the underlying implementation, is this incorrect?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失与倦" 2024-11-07 21:57:49

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

Since you want to hide the fact you are using xn namespace in your implementation, you should not put that in the library header file. The simplest way to solve this problem is to use the pimpl idiom.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文