英文:
How to solve C++ Warning C4251
问题
You need to modify the MyClassImpl
class to have a DLL interface. You can do this by adding the __declspec(dllexport)
attribute to the MyClassImpl
class, like this:
class __declspec(dllexport) MyClassImpl
{
public:
private:
const String Name;
};
This will allow MyClassImpl
to be used by clients of the MyClass
class without triggering the C4251 warning.
英文:
I need to expose MyClass with dllexport. But I have this Warning(C4251).
Code
class MyClassImpl
{
public:
private:
const String Name;
};
class __declspec(dllexport) MyClass {
public :
private:
const MyClassImpl data;
};
Warning
Severity Code Description Project File Line Suppression State
Warning C4251
'MyClass::data': class 'MyClassImpl' needs to have dll-interface to be used by clients of class 'MyClass'
C/C++ - Command line
/permissive- /ifcOutput "x64\Debug\" /GS /GL /Zc:preprocessor /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"x64\Debug\vc143.pdb" /Zc:inline /fp:precise /D "NDEBUG" /D "MYTESTLIB_EXPORTS" /D "_WINDOWS" /D "_USRDLL" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /std:c17 /Gd /Oi /MD /std:c++20 /FC /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\" /Fp"x64\Debug\MytestLib.pch" /diagnostics:column
Linker - Command line
/OUT:"I:\XProjects\MyTestLibWindows\x64\Debug\MyTestLib.dll" /MANIFEST /LTCG:incremental /NXCOMPAT /PDB:"I:\XProjects\MyTestLibWindows\x64\Debug\MyTestLib.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" "botan.lib" "icudt.lib" "icuin.lib" "icuio.lib" "icutest.lib" "icutu.lib" "icuuc.lib" /IMPLIB:"I:\XProjects\MyTestLibWindows\x64\Debug\MyTestLib.lib" /DEBUG /DLL /MACHINE:X64 /OPT:REF /PGD:"I:\XProjects\MyTestLibWindows\x64\Debug\MyTestLib.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:NO /ManifestFile:"x64\Debug\MyTestLib.dll.intermediate.manifest" /LTCGOUT:"x64\Debug\MyTestLib.iobj" /OPT:ICF /ERRORREPORT:PROMPT /ILK:"x64\Debug\MyTestLib.ilk" /NOLOGO /LIBPATH:"I:\XProjects\MyTestLibWindows\modules\ICU4c-73.1-Windows-x64-Release\lib64" /LIBPATH:"I:\XProjects\MyTestLibWindows\modules\Botan-2.19.3-Windows-x64-Debug\lib" /TLBID:1
How I have to create a DLL interface?
答案1
得分: 2
这个警告告诉您没有东西可以导出。当您将 __declspec(dllexport)
应用于一个类时,这相当于将 __declspec(dllexport)
应用于该类的每个方法。
您没有声明任何方法。
请参阅Microsoft Learn。
英文:
The warning is telling you that there's nothing to export. When you apply __declspec(dllexport)
to a class, that is the same as applying __declspec(dllexport)
to every method of the class.
You don't have any methods declared.
See Microsoft Learn
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论