生成导出包含 ATL::CString 成员的类的 DLL 时警告 C4251 [英] Warning C4251 when building a DLL that exports a class containing an ATL::CString member

查看:23
本文介绍了生成导出包含 ATL::CString 成员的类的 DLL 时警告 C4251的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将基于 ATL 的静态库转换为 DLL,并且在任何使用 ATL CString 类(在 atlstr.h 中找到)的导出类上收到以下警告:

I am converting an ATL-based static library to a DLL and am getting the following warning on any exported classes that use the ATL CString class (found in atlstr.h):

警告 C4251:'Foo::str_':类'ATL::CStringT'需要使用 dll 接口'Foo' 类的客户

warning C4251: 'Foo::str_' : class 'ATL::CStringT' needs to have dll-interface to be used by clients of class 'Foo'

我正确地将 Foo 类声明为通过 __declspec(dllexport) 导出的.这是我可以放心忽略的警告还是我做错了什么?DLL 项目设置设置为与 ATL 动态链接,但这似乎没有任何区别.

I am correctly declaring the Foo class as exported via __declspec(dllexport). Is this a warning I can safely ignore or am I doing something wrong? The DLL project settings are set to dynamically link with ATL, but this doesn't seem to make any difference.

例如:

#ifdef DLLTEST_EXPORTS
#define DLLTEST_API __declspec(dllexport)
#else
#define DLLTEST_API __declspec(dllimport)
#endif

// This class is exported from the DLLTest.dll
class DLLTEST_API Foo
{
public:
 Foo();
 CString str_; // WARNING C4251 HERE
};

此 DLL 的所有客户端也将使用 ATL.

All clients of this DLL will also be using ATL.

推荐答案

这个线程 给出了我认为更好的答案,作者:道格·哈里森(VC++ MVP):

This thread gives what I consider a better answer, by Doug Harrison (VC++ MVP):

[此警告]在您使用时发出在一个非 dllexported 类 Xdllexported class Y. 有什么不好关于那个?好吧,假设 Y 有一个调用 a 的内联函数 y_f属于 X 的函数 x_f 是也不内联.如果 y_f 是内联的在一些没有的客户里面静态链接X,链接将失败,因为找不到 x_f.

[This warning is] emitted when you use a non-dllexported class X in a dllexported class Y. What's so bad about that? Well, suppose Y has an inline function y_f that calls a function x_f belonging to X that is not also inline. If y_f is inlined inside some client that doesn't statically link X, the link will fail, because x_f won't be found.

这篇关于生成导出包含 ATL::CString 成员的类的 DLL 时警告 C4251的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆