Explorar o código

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) 加入到需要导出的符号之上
zinface %!s(int64=2) %!d(string=hai) anos
pai
achega
607ca11d92
Modificáronse 1 ficheiros con 13 adicións e 2 borrados
  1. 13 2
      src/plugin/external-plugin/external-plugin/base.cpp

+ 13 - 2
src/plugin/external-plugin/external-plugin/base.cpp

@@ -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
     }
-};
+};
+
+}