我正在使用Visual Studio,并且正在处理A类中的一些C++代码,它们的工作方式如下所示
class A
{
public:
//......
static void foo();
};导出类B:
class __declspec(dllexport) B
{
public:
//...
void bar()
{
A::foo();
}
};A和B被编译成AB.dll (和AB.lib)。现在是主程序:
int main()
{
B b;
b.bar();
return 0;
}
When compiling the main program and linking it to AB.lib,
it complains about the A::foo() as unresolved external symbol
(in this case A::foo is a static function).
Do I need to somehow export A::foo() or could it be that
I introduce errors somewhere? Any help is appreciated.
Modified:
1) Sorry for the type, it should be dllexport, not dllimport
2) in my actual project, the implementation is in .cpp files. They are not inline functions.
Thanks.发布于 2016-03-24 05:13:39
我假设显示的代码在您的.h头文件中,那么当您的头文件说:
class __declspec(dllimport) B
{
public:
//...
void bar()
{
A::foo();
}
};首先:你说导入了B类,它适用于你的主应用程序,但不适用于你的dll。
第二: B::bar()不是从dll导入的,而是直接在你的主应用程序中实现的(编译器直接在你的头文件中读取,而不是试图从dll导入)
建议:
首先:重新定义头文件,如下所示:
class __declspec(dllimport) B
{
public:
//...
void bar();
};并在dll工程的cpp文件中实现方法B::bar
第二:从头文件中删除A类(如果可以的话)
https://stackoverflow.com/questions/36186739
复制相似问题