我正在尝试使用clang(无emscripten)为WebAssembly编译我的C库,并且在clang
版本8.0.1
下可以正常编译,但是在clang
版本9.0.0
下可以正常编译。报告的错误为wasm-ld: error: ….o: undefined symbol: __heap_base
。 __heap_base
是否已替换为其他符号?
该库是开源的,编译说明可以在here中找到
这似乎是9.0.0中的错误。 ToT或8.0.0似乎没有发生这种情况。
简单的复制案例:
extern void* __heap_base;
void* a = &__heap_base;
void _start() {
}
构建方式:
$ clang --target=wasm32 test.c -nostdlib -Wl,-no-gc-sections
使用9.0.0:
wasm-ld: error: /tmp/test-551a5c.o: undefined symbol: __heap_base
clang-9: error: linker command failed with exit code 1 (use -v to see invocation)
这应在llvm错误跟踪器中作为错误打开。
实际上,我相信我找到了罪魁祸首:9.0.0
中的链接器似乎需要--export=__heap_base
(-Wl,--export=__heap_base
为clang
)。这适用于我的项目。