WebAssembly-cn / WebAssembly-cn/pit

emscripten遇到warning: unresolved symbol: ***funcName***

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
3
Forks
0
PR merge metrics
No merged PRs in 30d

Description

运行
```
emcc -s WASM=1 -O3 -o program.js program.cpp --js-library library.js
```

返回

```
warning: unresolved symbol: _Z6funcNamev
```

program.js
```
#include
#include

// 定义数组大小
#define N 100

// 防止 C++ 函数名被 Mangling
#ifdef _cplusplus
extern "C" {
#endif
// 预置函数,暴露给 JS 进行处理
extern void checku ();

void EMSCRIPTEN_KEEPALIVE abc () {
char a[] = "username";
checku();
}
#ifdef _cplusplus
}
#endif
```
library.js
```
mergeInto(LibraryManager.library, {
checku: function() {
console.log(123)
}
});
```

笔误,踩了一个大坑。

```
#ifdef _cplusplus
extern "C" {
#endif
```
其实是 `__cplusplus` 前面两个下划线
```
#ifdef __cplusplus
extern "C" {
#endif
```

添加这个判断防止 C++ 函数名被 Mangling.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.