plugin/external-plugin: 缺少 extern "C" 无法加载 dll 的问题

本次记录 extern "C" 在 Windows 中的符号生成规则:
1. 无 extern "C" 包含的部分生成的符号为
    struct externalplugin plugin
    struct externalplugin * plugins
2. 使用 extern "C" 包含之后
    plugin
    plugins
3. 将 __declspec(dllexport) 加入到需要导出的符号之上
This commit is contained in:
zinface 2023-03-29 23:55:08 +08:00
parent 9130083e8f
commit 607ca11d92
1 changed files with 13 additions and 2 deletions

View File

@ -1,4 +1,4 @@
#include "interface/external.h"
#include "interface/external.h"
// #include <stdio.h>
// #include <string.h>
@ -22,12 +22,21 @@ void openLinkNotepad(std::string &content) {
content = "https://gitee.com/cxasm/notepad--";
}
extern "C"
{
#ifdef WIN32
__declspec(dllexport)
#endif
struct externalplugin plugin = {
.type = ActionBase,
.meta = "打印 Hello",
.func = sayHello,
};
#ifdef WIN32
__declspec(dllexport)
#endif
struct externalplugin plugins[] = {
{
.type = ActionBase,
@ -56,4 +65,6 @@ struct externalplugin plugins[] = {
{
.type = ActionUnknow
}
};
};
}