编译器警告 C4251:导出 *.dll 中的类时出现问题
编辑:请原谅我的笨蛋,我以前从未实现过包装器 .dll! :S
我一直在修改一些最近发布的 Kinect 传感器 hack(即 OpenKinect 和 OpenNI),我现在尝试将功能包装在 *.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您想隐藏在实现中使用
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.