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

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

问题描述

我正在将基于ATL的静态库转换为DLL,并且在使用ATL c> 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'
需要要使用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.

推荐答案

这个线程给出了我认为更好的答案,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的
函数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.

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

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