如何解决WSL中出现的‘ld terminated with signal 9 [Killed]’错误?
WSL编译py-polars时链接器被终止的解决方法
问题背景
环境信息
- Python 3.11
- rustc 1.74.0-nightly
- 运行环境:Windows 11 下的 WSL(Ubuntu 20.04)
触发操作
git clone git@github.com:<username>/polars.git cd polars rustup toolchain install nightly --component miri cd py-polars make test
核心错误日志
Compiling py-polars v0.19.6 (/home/user/projects/polars/py-polars) error: linking with `cc` failed: exit status: 1 ... = note: collect2: fatal error: ld terminated with signal 9 [Killed] compilation terminated. error: could not compile `py-polars` (lib) due to previous error 💥 maturin failed ... make: *** [Makefile:23: build] Error 1
解决步骤
1. 扩容WSL内存
链接器被杀死(signal 9)通常是内存不足导致,修改WSL配置提升内存:
- 在Windows用户目录(
C:\Users\<你的用户名>)创建/编辑.wslconfig:
[wsl2] memory=8GB swap=4GB
- 执行
wsl --shutdown重启WSL生效。
2. 启用Cargo增量编译
降低单次编译的内存占用,编辑py-polars/Cargo.toml的[profile.dev]段:
[profile.dev] incremental = true # 保留原有配置,新增上述行
3. 限制并行编译任务数
减少同时编译的任务量,缓解内存压力:
export CARGO_BUILD_JOBS=2 make test
4. 补全系统编译依赖
确保Ubuntu环境的编译工具完整:
sudo apt update && sudo apt install build-essential libssl-dev pkg-config
内容的提问来源于stack exchange,提问作者OES
相关产品推荐
相关产品推荐

