【发布时间】:2019-06-30 04:16:29
【问题描述】:
我正在使用 def 文件从 dll 中导出一些静态函数和变量。在导入 dll 后访问静态变量时,程序崩溃。任何想法为什么会发生这种情况?我正在使用 VS2017,Windows SDK 10.0.17763.0。
图书馆.h
struct DLLEXPORT A {
static int a;
static int get();
};
struct B {
static int b;
static int get();
};
库.cpp
int A::a = 0;
int A::get() {return a;}
int B::b = 0;
int B::get() {return b;}
库.def
LIBRARY
EXPORTS
?b@B@@2HA
?get@B@@SAHXZ
main.cpp
int main() {
int a = A::get(); // Works fine
int b = B::get(); // Works fine
A::a = 1; // Works fine
B::b = 1; // CRASH (Access violation writing location ...)
return 0;
}
【问题讨论】:
-
我认为您还需要导出 B::b;
-
@SHR 是在def文件中导出的,不是吗?否则 OP 会得到未解决的外部符号链接器错误。
标签: c++ visual-c++ dll