• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

交叉编译rust-openssl crate

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

转自:https://www.javaroad.cn/questions/121768

我在Debian机器上,我想为我的Raspberry Pi 2交叉编译一个项目 . 我已经设法用一个简单的hello世界使用rustup,但无法弄清楚如何交叉编译rust-openssl crate .

我用arm-linux-gnueabihf-gcc编译了openssl并将其安装在我的 home/opensslArm 目录中 .

我跑的时候

OPENSSL_LIB_DIR=/home/johann/opensslArm/lib OPENSSL_INCLUDE_DIR=/home/johann/opensslArm/include cargo build --target=armv7-unknown-linux-gnueabihf

我收到此错误:

failed to run custom build command for `openssl-sys-extras v0.7.11`
Process didn't exit successfully: `/home/johann/projects/test/target/debug/build/openssl-sys-extras-e1c84960cd35bc93/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("armv7-unknown-linux-gnueabihf")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("armv7-unknown-linux-gnueabihf")
debug=true opt-level=0
HOST = Some("x86_64-unknown-linux-gnu")
TARGET = Some("armv7-unknown-linux-gnueabihf")
TARGET = Some("armv7-unknown-linux-gnueabihf")
HOST = Some("x86_64-unknown-linux-gnu")
CC_armv7-unknown-linux-gnueabihf = None
CC_armv7_unknown_linux_gnueabihf = None
TARGET_CC = None
CC = None
HOST = Some("x86_64-unknown-linux-gnu")
TARGET = Some("armv7-unknown-linux-gnueabihf")
HOST = Some("x86_64-unknown-linux-gnu")
CFLAGS_armv7-unknown-linux-gnueabihf = None
CFLAGS_armv7_unknown_linux_gnueabihf = None
TARGET_CFLAGS = None
CFLAGS = None
running: "arm-linux-gnueabihf-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-fPIC" "-march=armv7-a" "-o" "/home/johann/projects/test/target/armv7-unknown-linux-gnueabihf/debug/build/openssl-sys-extras-e1c84960cd35bc93/out/src/openssl_shim.o" "-c" "src/openssl_shim.c"
ExitStatus(ExitStatus(256))


command did not execute successfully, got: exit code: 1



--- stderr
In file included from src/openssl_shim.c:1:0:
/usr/include/openssl/hmac.h:61:34: fatal error: openssl/opensslconf.h: No such file or directory
compilation terminated.
thread '<main>' panicked at 'explicit panic', /home/johann/.cargo/registry/src/github.com-88ac128001ac3a9a/gcc-0.3.28/src/lib.rs:840
note: Run with `RUST_BACKTRACE=1` for a backtrace.

 

如果我导出有问题的变量,我会得到相同的错误 .

我不知道我应该做什么,我不是交叉编译的专家 . 有没有人设法做到这一点?

编辑:我使用的是rust-openssl 0.7.11 . 升级到0.7.13修复了这个问题(我现在可以看到货物编译rust-openssl依赖而没有错误)但我现在又有另一个:

error: linking with `arm-linux-gnueabihf-gcc` failed: exit code: 1
...

note: /usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/bin/ld: /home/johann/opensslArm/lib/libssl.a(s23_meth.o): relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/home/johann/opensslArm/lib/libssl.a: error adding symbols: Bad value

如何添加 -fPIC 标志?我应该使用特定标志重新编译opensslArm吗?

回答:

配置openssl编译时必须传递 shared 选项(这将使 -fPIC 参数传递给编译器) .

这是一系列命令,我用它来测试交叉编译打印openssl版本的Rust程序:

cd /tmp

wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar xzf openssl-1.0.1t.tar.gz
export MACHINE=armv7
export ARCH=arm
export CC=arm-linux-gnueabihf-gcc
cd openssl-1.0.1t && ./config shared && make && cd -

export OPENSSL_LIB_DIR=/tmp/openssl-1.0.1t/
export OPENSSL_INCLUDE_DIR=/tmp/openssl-1.0.1t/include
cargo new xx --bin
cd xx
mkdir .cargo
cat > .cargo/config << EOF
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
EOF

cat > src/main.rs << EOF
extern crate openssl;

fn main() {
    println!("{}", openssl::version::version())
}
EOF

cargo add openssl # requires cargo install cargo-add
cargo build --target armv7-unknown-linux-gnueabihf

Testing the compiled program on the host computer

Setting OPENSSL_STATIC 使 rust-openssl 静态链接 . 如果使用 rust-openssl 的静态链接版本,为armhf( crossbuild-essential-armhf on Debian)和 qemu-static 安装libc,则可以使用以下命令运行已编译的程序:

qemu-arm-static target/armv7-unknown-linux-gnueabihf/debug/xx

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
matlab 制作gif动画发布时间:2022-07-18
下一篇:
win7MATLAB7运行时出现错误javaxunknown及解决发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap