安装¶
前置依赖¶
Link 用 Rust 编写,需要 Rust 工具链才能从源码构建。
Rust 工具链¶
使用 rustup 安装:
MSVC 工具链(推荐):
需安装 Visual Studio Build Tools,包含: - MSVC v143 - VS 2022 C++ x64/x86 build tools - Windows 11 SDK
GNU 工具链(备选):
验证安装:
Python(可选,用于 Python FFI)¶
如需使用 extern "python" 调用 Python 函数,需安装 Python 3.8+:
或从 python.org 下载。 安装时勾选 "Add Python to PATH"。
C++ 编译器(可选,用于 C++ FFI)¶
如需编译自己的 C++ 共享库供 Link 调用:
从源码构建¶
构建产物位于 target/release/link(Windows 上为 link.exe)。
安装到 PATH¶
# 创建符号链接到用户 bin 目录
$binDir = "$env:USERPROFILE\bin"
New-Item -ItemType Directory -Force -Path $binDir | Out-Null
Copy-Item ".\target\release\link.exe" "$binDir\link.exe"
# 将 bin 目录加入 PATH(永久)
[Environment]::SetEnvironmentVariable(
"Path",
"$binDir;" + [Environment]::GetEnvironmentVariable("Path", "User"),
"User"
)
# 刷新当前会话
$env:Path = "$binDir;$env:Path"
# 验证
link --version
验证安装¶
运行测试套件确认环境正常:
预期输出:
test result: ok. 41 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
VS Code 扩展(可选)¶
仓库内置 VS Code 语法高亮扩展,位于 editors/vscode/:
按 F5 启动扩展开发宿主窗口,打开 .link 文件即可看到语法高亮。
故障排查¶
cargo build 报错 "link.exe not found"¶
Windows 上未安装 MSVC Build Tools。解决方法:
- 安装 Visual Studio Build Tools(见前置依赖)
- 或切换到 GNU 工具链:
rustup default stable-x86_64-pc-windows-gnu
Python FFI 报错 "Failed to load python3.dll"¶
Python 未在 PATH 中。解决方法:
- Windows:确认安装时勾选了 "Add Python to PATH"
- Linux:确认安装了
python3-dev(Debian/Ubuntu)或python3-devel(RHEL/CentOS) - 也可手动指定 DLL 路径:
extern "python" module "C:/Python311/python311.dll"
C++ FFI 报错 "Failed to load library"¶
C++ 共享库路径错误或架构不匹配。检查:
- DLL/SO 路径是否正确(相对路径基于运行目录)
- 架构是否匹配(64 位 Link 需要 64 位 DLL)
- C++ 函数是否用
extern "C"导出(否则会被名称修饰)