Solana SPL 程序编译
代码Clone
git clone https://github.com/solana-program/token.git
cd token
git checkout program@v3.5.0基础环境
# 安装nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
source ~/.bashrc
# 安装node
nvm install 20
node -v
# 安装pnpm
npm install -g pnpm安装依赖
pnpm install编译
cd program/
cargo build-sbf默认编译可能出现以下错误
[2025-04-25T09:39:35.004769959Z ERROR cargo_build_sbf] Failed to obtain package metadata: `cargo metadata` exited with an error: error: current package believes it's in a workspace when it's not:
current: /mnt/d/github/token/program/Cargo.toml
workspace: /mnt/d/github/token/Cargo.toml
this may be fixable by adding `program` to the `workspace.members` array of the manifest located at: /mnt/d/github/token/Cargo.toml
Alternatively, to keep it out of the workspace, add the package to the `workspace.exclude` array, or add an empty `[workspace]` table to the package's manifest.解决
在 program 目录的 Cargo.toml 文件中添加空的 [workspace] 表修改 programCargo.toml,在第一行增加
[workspace] // 增加此行
[package]
name = "spl-token"
version = "3.5.0"
...执行成功后,程序编译出现在program\target\deploy\spl_token.so