该问题通常是由于使用了交叉编译器或特殊编译选项所致。要解决此问题,可以在Cargo.toml中添加以下内容:
[target.x86_64-apple-darwin] rustflags = ["-C", "link-arg=-Wl,-install_name,@rpath/libfoo.dylib"]
其中,target.x86_64-apple-darwin是指定后缀目录的名称,rustflags是传递给Rust编译器的选项。将以上示例中的libfoo.dylib替换为您的库名称即可。
另外,也可以将默认的构建目录更改为target/debug,可以在Cargo.toml中添加以下内容:
[profile.dev] target-dir = "target/debug"
这将使所有构建文件保持在target/debug目录下。