我刚刚意识到,当我使用regex_macros
crate 时,通过 Cargo 创建的 Rust 二进制文件是动态链接的。这有点问题,因为当我更新到更新版本的regex_macros
.
有办法解决吗?
这是一个最小的例子:
#![feature(plugin)]
#[plugin]
extern crate regex_macros;
fn main() {}
编译它并查看链接的内容揭示了这一点:
uh@macaron:~/linking-test (master)$ otool -L target/linking-test
target/linking-test:
/Users/uh/linking-test/target/deps/libregex_macros-bdbdbfedad0748ac.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/librustc-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libflate-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libgetopts-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/librustc_back-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libsyntax-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libfmt_macros-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libarena-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libterm-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libgraphviz-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/librbml-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libserialize-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/liblog-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/librustc_llvm-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
x86_64-apple-darwin/stage2/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
/usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
如您所见,第一个链接的 dylib 有一个进入项目所在目录的绝对路径,即使这样做cargo clean
也可能会破坏可执行文件。