DLL导出静态类方法
dllexport static class methods
我正在使用Visual Studio,并且正在处理一些C++代码,这些代码在第A
类中的工作方式如下:
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.
我假设显示的代码在您的 .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类(如果可以的话(
相关文章:
- c++, 在子类中,如何在没有对象的情况下访问父类的方法?
- 调用具有未标识类型的类的方法
- 是否可以使用基类非虚拟方法中的派生类虚拟方法?
- 静态 constexpr 类成员变量对多线程读取是否安全?
- 如何访问存储在 std::variant 中的类的方法
- 如何将类成员方法的参数列表自动填充写入可变参数?
- C ++类型特征:确保子类实现方法
- 静态 std::map instatiation 在类的方法中调用构造函数吗?
- 派生类调用父类的方法,该方法调用重写的虚拟方法调用错误的方法
- 将一个类的方法指针存储到另一个类中
- 通过基类接受方法转发派生 UniquePtr 的右值会移动引用而不是复制
- 从内部类中的方法从包含类调用方法
- 对纯抽象类中方法的未定义引用
- 如何在该接收类之外声明嵌套类的方法
- C++初始化之前派生类调用基类的方法
- 如果类"A"具有指向另一个类的指针,则"B" A 可以访问 B 类公共方法
- 对静态重载(类)函数/方法的调用是不明确的
- 为什么可以从实例化基类对象的投射指针调用非静态派生类方法
- 为什么我不能使用 GetProcAddress 在 DLL 中调用C++静态类工厂方法?
- 让基类的方法使用继承类的静态成员变量...可能?