Skip to content

Commit 909bfb6

Browse files
committed
解决 multiple definition of 的编译错误
1 parent 2677b8d commit 909bfb6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

native/cpp/quickjs_extend_libraries.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#ifndef QUICKJS_EXTEND_LIBRARIES
2+
#define QUICKJS_EXTEND_LIBRARIES
3+
14
#include <string>
25
#include "../quickjs/quickjs.h"
36

@@ -338,4 +341,6 @@ const char *CONSOLE = R"lit(// Init format at first.
338341
void loadExtendLibraries(JSContext *ctx) {
339342
JS_Eval(ctx, DATE_POLYFILL, strlen(DATE_POLYFILL), "date-polyfill.js", JS_EVAL_TYPE_GLOBAL);
340343
JS_FreeValue(ctx, JS_Eval(ctx, CONSOLE, strlen(CONSOLE), "console.js", JS_EVAL_TYPE_GLOBAL));
341-
}
344+
}
345+
346+
#endif //QUICKJS_EXTEND_LIBRARIES

wrapper-js/src/index.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ if (existDir(FILE_CPP)) {
1616

1717
// 以下开始写入扩展库代码
1818

19+
code += "#ifndef QUICKJS_EXTEND_LIBRARIES" + LINE
20+
code += "#define QUICKJS_EXTEND_LIBRARIES" + LINE
21+
code += LINE
22+
1923
// include 引用文件
2024
code += `#include <string>` + LINE
2125
code += `#include "../quickjs/quickjs.h"` + LINE
@@ -56,5 +60,8 @@ if (existDir(FILE_CPP)) {
5660
// 入口方法结尾
5761
code += "}"
5862

63+
code += LINE.repeat(2)
64+
code += "#endif //QUICKJS_EXTEND_LIBRARIES"
65+
5966
writeToFile(FILE_CPP, code)
6067
})()

0 commit comments

Comments
 (0)