我正在尝试将此示例代码从 rust 编译为 wasm。它是一个生锈的板条箱,可让您创建/编写 excel 文件。我已经成功地使用cargo run
运行它。
不幸的是,当我尝试将其编译为 Web 程序集时,我遇到了一个错误,指出在编译 bzip2-sys(一个生锈的箱子(时找不到库<stdlib.h>
,一个常见的 C 库。
当我第一次尝试编译它时,它提示我安装 clang 我从这里开始(Windows 的预构建二进制文件(64 位和 32 位((,并且我已经C:Program FilesLLVMbin
包含在系统 Path 环境变量中。我还安装了MinGW-w64,以及带有Visual C++构建工具的Visual Studio 2017。
您可以在下面看到Visual Studio Code中生成的整个错误。
PS C:UsersUserDesktopexcel-test> wasm-pack build
[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
Compiling libc v0.2.71
Compiling pkg-config v0.3.17
Compiling cc v1.0.54
Compiling crc32fast v1.2.0
Compiling cfg-if v0.1.10
Compiling adler32 v1.0.4
Compiling podio v0.1.7
Compiling miniz_oxide v0.3.6
Compiling time v0.1.43
Compiling flate2 v1.0.14
Compiling bzip2-sys v0.1.9+1.0.8
error: failed to run custom build command for `bzip2-sys v0.1.9+1.0.8`
Caused by:
process didnt exit successfully: `C:UsersUserDesktopexcel-testtargetreleasebuildbzip2-sys-aa88969feaab6a44build-script-build` (exit code: 1)
--- stdout
TARGET = Some("wasm32-unknown-unknown")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-pc-windows-msvc")
CC_wasm32-unknown-unknown = None
CC_wasm32_unknown_unknown = None
TARGET_CC = None
CC = None
CFLAGS_wasm32-unknown-unknown = None
CFLAGS_wasm32_unknown_unknown = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
running: "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "bzip2-1.0.8" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "C:\Users\User\Desktop\excel-test\target\wasm32-unknown-unknown\release\build\bzip2-sys-03c492d40657ce9f\out\lib\bzip2-1.0.8/blocksort.o" "-c" "bzip2-1.0.8/blocksort.c"
cargo:warning=In file included from bzip2-1.0.8/blocksort.c:22:
cargo:warning=bzip2-1.0.8/bzlib_private.h:25:10: fatal error: 'stdlib.h' file not found
cargo:warning=#include <stdlib.h>
cargo:warning= ^~~~~~~~~~
cargo:warning=1 error generated.
exit code: 1
--- stderr
error occurred: Command "clang" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-I" "bzip2-1.0.8" "-D_FILE_OFFSET_BITS=64" "-DBZ_NO_STDIO" "-o" "C:\Users\User\Desktop\excel-test\target\wasm32-unknown-unknown\release\build\bzip2-sys-03c492d40657ce9f\out\lib\bzip2-1.0.8/blocksort.o" "-c" "bzip2-1.0.8/blocksort.c" with args "clang" did not execute successfully (status code exit code: 1).
Error: Compiling your crate to WebAssembly failed
Caused by: failed to execute `cargo build`: exited with exit code: 101
full command: "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"
PS C:UsersUserDesktopexcel-test>
假设文件是某个目录,您可能需要帮助 clang 找到它:
https://clang.llvm.org/docs/ClangCommandLineReference.html#include-path-management
控制如何将 #includes 解析为文件的标志。
-I, --include-directory , --include-directory=