在构建导出包含ATL :: CString成员的类的DLL时,警告C4251 [英] Warning C4251 when building a DLL that exports a class containing an ATL::CString member
问题描述
我正在将一个基于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_':class
'ATL :: CStringT'
使用类'Foo'的客户端使用dll接口
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.
推荐答案
这个线程给出了我认为更好的答案,由Doug Harrison(VC ++ MVP):
This thread gives what I consider a better answer, by Doug Harrison (VC++ MVP):
[此警告是]在
dllexported类Y中使用
a非dllexported类X时发出。这是很糟糕
?嗯,假设Y有一个
内联函数y_f,它调用一个
函数x_f属于X,即
也不是inline。如果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屋!