【问题标题】:Alternative solutions to missing shared libraries after cross compilation?交叉编译后缺少共享库的替代解决方案?
【发布时间】:2020-01-04 15:08:05
【问题描述】:

我首先将我的 Rust 项目交叉编译到 linux 目标

cargo build --target x86_64-unknown-linux-gnu

然后在我的本地 ubuntu 上运行 ldd,链接器就可以正常工作了。

linux-vdso.so.1 (0x00007fffddc62000)
libssl.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f6d34500000)
libcrypto.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f6d340b0000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6d33ea0000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f6d33c90000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6d33a70000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f6d33850000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6d33440000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6d35a00000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6d330a0000)

但在我的目标操作系统上,ldd 找不到库

libssl.so.1.0.0 => not found
libcrypto.so.1.0.0 => not found
/lib64/libc.so.6 => version `GLIBC_2.18' not found

实际上我在LD_LIBRARY_PATH 下安装了libssl.so.10libcrypto.so.10。不幸的是,我无法安装 Rust 所需的 1.0.0 版本的共享库。

我已阅读Rust Cross,推荐的解决方案是安装缺少的共享库。不幸的是,这对我来说是不可能的。所以我正在寻找缺少库的替代解决方案。

libssl.so.1.0.0libcrypto.so.1.0.0 听起来很古老。如何告诉cargo 使用更高版本?

我该如何处理/lib64/libc.so.6 => version GLIBC_2.18 not found

【问题讨论】:

  • 实际上,lib{ssl,crypto}.so.6*.so.1.0.0 对应的版本老很多。我的猜测是您的编译器系统比目标系统更现代。如果你不能升级目标也许你可以降级交叉编译器?

标签: rust cross-compiling rust-cargo


【解决方案1】:

根据thisGLIBC_2.18无法安装到RHEL7。我放弃了动态链接库。

这个post 帮助了我。解决办法是:

[dependencies]
nats = "*"
protobuf = { version = "~2.0" }
# Add openssl-sys as a direct dependency so it can be cross compiled to
# x86_64-unknown-linux-musl using the "vendored" feature below
openssl-sys = "*"

[features]
# Force openssl-sys to staticly link in the openssl library. Necessary when
# cross compiling to x86_64-unknown-linux-musl.
vendored = ["openssl-sys/vendored"]

这样我可以编译成没有库依赖的单个可执行文件:

cargo build --target=x86_64-unknown-linux-musl --features vendored

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    • 1970-01-01
    • 2022-07-18
    • 2017-06-07
    相关资源
    最近更新 更多