在dll-interface中使用stl-classes作为处理警告c4251的常用做法不是一个好习惯:class ...需要有dll-interface解释.给出了一个例子:
#include <iostream>
#include <string>
#include <vector>
class __declspec(dllexport) HelloWorld
{
public:
HelloWorld()
{
abc.resize(5);
for(int i=0; i<5; i++)
abc[i] = i*10;
str="hello the world";
}
~HelloWorld()
{
}
std::vector<int> abc;
std::string str;
};
Run Code Online (Sandbox Code Playgroud)
编译此文件时,可以观察到以下警告:
warning C4251: 'HelloWorld::str' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'HelloWorld'
warning C4251: 'HelloWorld::abc' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'HelloWorld'
Run Code Online (Sandbox Code Playgroud)
那么问题是我们如何在不使用STL类向量和字符串的情况下实现相同的功能.我能想到的一个实现如下:
class __declspec(dllexport) HelloWorld2 …Run Code Online (Sandbox Code Playgroud) 我继承了一个庞大的C++多项目解决方案,其中包含许多动态库但没有任何动态库
__declspec(dllexport)
Run Code Online (Sandbox Code Playgroud)
我了解到一个人不一定要插入任何dllexport(会有很多工作),但除了相应的.dll之外,还可以使用.def文件.
为了尝试我从这里建立一个"DLL Hello World"项目,从标题中删除了dllexport并且......拼命地失败了.用已引用的页面来说,我的关键问题是如何
"[..] use the .def file when building the DLL."
Run Code Online (Sandbox Code Playgroud)
我的.def文件是(我只使用Add方法尝试代码):
LIBRARY MathFuncsDll
EXPORTS
?Add@MyMathFuncs@MathFuncs@@SANNN@Z
Run Code Online (Sandbox Code Playgroud)
在Visual Studio 2010中构建DLL以便导出Add方法时如何使用它?
如何找出将分配给每个方法名称的装饰名称?我试图找出装饰名称是什么,以便我可以在DLL中导出它.