首页 > 解决方案 > 使用 Emscripten 构建时出现链接器错误

问题描述

我有一个现有的 C++ 库,我正在尝试使用 Emscripten 将其移植到 Wasm。

库本身构建良好:

[ 33%] Linking CXX static library libFoo.a
[ 33%] Built target Foo

但是,我在构建测试套件时遇到了链接器错误:

[ 67%] Linking CXX executable FooTests_Run_Wasm.html
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Tests/FooTests_Run_Wasm.html] Error 1
make[1]: *** [Tests/CMakeFiles/FooTests_Run_Wasm.dir/all] Error 2
make: *** [all] Error 2
emmake: error: 'make' failed (returned 2)

这是我正在使用的链接器标志:

-fexceptions                    
-pthread
--bind                         
-s ALLOW_MEMORY_GROWTH=1                         
-s ERROR_ON_UNDEFINED_SYMBOLS=0
-s FILESYSTEM=0                         
-s LLD_REPORT_UNDEFINED=1                         
-s PROXY_TO_PTHREAD=1                         
-s SAFE_HEAP=1                         
-s STRICT=1 

标签: c++linkeremscripten

解决方案


推荐阅读