最近,我一直试图将一个cpp文件转换为没有emscripten的wasm文件,并且运行时出现了一些错误,例如,当我运行以下命令时:
clang++ --target=wasm32 -nostdlib -O3 -o public/main.o -c src/*.cpp
wasm-ld --no-entry --export-all --lto-O3 --allow-undefined --import-memory public/main.o -o public/main.wasm它给了我这个错误:
wasm-ld: error: unknown file type public/main.o以下是我目前拥有的clang和lld的版本:
clang version 12.0.1
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /nix/store/jp4r5v8pla63qam5w34jvfyfmq8p74am-clang-12.0.1/bin
LLD 12.0.1另外,我在复制上运行代码
谢谢
发布于 2022-07-10 08:38:09
好的,通过这个命令,它可以工作:D
clang++ --target=wasm32 -emit-llvm -c -S -o public/files/main.ll src/main.cpp
llc -march=wasm32 -filetype=obj -o public/files/main.o public/files/main.ll
wasm-ld --no-entry --export-all -o public/main.wasm public/files/main.o唯一的问题是您需要创建一些新文件(main.ll和main.o),但这并不重要。
我得到解的地方在这里:https://surma.dev/things/c-to-webassembly/index.html,它真的很有用
https://stackoverflow.com/questions/72894208
复制相似问题