Emscripten C++ to WASM with Classes - "error: undefined symbol"

Emscripten C++ to WASM with Classes - "error: undefined symbol"

我有一个非常简单的 C++ 项目(删除了尽可能多的代码,直到问题仍然存在。)运行 em++ 总是导致错误,error: undefined symbol

main.cpp

#include "edgeguard.hpp"

int main()
{
    EdgeGuardConfig core = EdgeGuardConfig::BuildEdgeGuard();
}

edgeguard.cpp

#include "edge-guard.hpp"

EdgeGuardConfig EdgeGuardConfig::BuildEdgeGuard()
{
}

edgeguard.hpp

class EdgeGuardConfig
{
public:
    static EdgeGuardConfig BuildEdgeGuard();
};

我使用的命令是em++ ./main.cpp --std=c++17 -o ~/edgeguard-wasm/edgeguard-ft90x.html

结果总是一样的:

error: undefined symbol: _ZN15EdgeGuardConfig14BuildEdgeGuardEv (referenced by top-level compiled C/C++ code)
warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
warning: __ZN15EdgeGuardConfig14BuildEdgeGuardEv may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
Error: Aborting compilation due to previous errors
em++: error: '/home/nessdan/code/emsdk/node/14.18.2_64bit/bin/node /home/nessdan/code/emsdk/upstream/emscripten/src/compiler.js /tmp/tmpqwnlcp5h.json' failed (returned 1)

我尝试过的其他一些事情:

  1. 使用EMSCRIPTEN_KEEPALIVE
  2. extern "C"
  3. 中包装东西
  4. 运行 -s ERROR_ON_UNDEFINED_SYMBOLS=0(命令完成,但 HTML 输出在我打开控制台时记录错误。)
  5. 运行 -s LINKABLE=1 -s EXPORT_ALL=1 - 没有任何变化,控制台输出相同。

我使用的是最新版本的 emscripten (3.1.6) 并在今天全新安装了它(我的 Windows 计算机上也安装了 运行,结果完全相同。)

感谢 Marc Glisse 的评论,我现在意识到我不仅需要传递 main.cpp,还需要传递所有相关的 .cpp 文件(我认为它会从包含的信息中提取信息 ‍♂️ )

正在编译