< 返回版块

jm-observer 发表于 2022-11-12 17:06

Tags:mipsel

  1. .cargo/config.toml配置如下:
[target.mipsel-unknown-linux-gnu]
linker = "mipsel-openwrt-linux-gcc"
rustflags = ["-L", "native=./resources/mipsel_openwrt_lib"
 , "-l", "iot_mipsel_1004kc_debugs"
 , "-l", "pthread"
    , "-l", "resolv"
    , "-C", "link-arg=-fPIC"
    ,"-C", "link-arg=-static"
 ]
  1. 编译命令:cargo build --target mipsel-unknown-linux-gnu
  2. file 文件:
root@7894ecc54983:/opt/iiotffi# file target/mipsel-unknown-linux-gnu/debug/ffi_pingan
target/mipsel-unknown-linux-gnu/debug/ffi_pingan: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /usr/lib/libc.so.1, with debug_info, not stripped
  1. 用mipsel-openwrt-linux-gcc编译c代码,用file查看文件:
root@7894ecc54983:/opt/demo_linux_mipsel_1004kc# make
mipsel-openwrt-linux-gcc -I../include -g -o main.o -c main.c
mipsel-openwrt-linux-gcc -I../include -g -o iot_interface.o -c iot_interface.c
mipsel-openwrt-linux-gcc ./main.o ./iot_interface.o -L../lib -liot_mipsel_1004kc_debug -lpthread -o sdk_test_aes
root@7894ecc54983:/opt/demo_linux_mipsel_1004kc# file sdk_test_aes
sdk_test_aes: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, interpreter /lib/ld-uClibc.so.0, with debug_info, not stripped

问题:为什么rust交叉编译生成程序的interpreter 是/usr/lib/libc.so.1。而直接编译是/lib/ld-uClibc.so.0。如果要使得rust交叉编译生成的也是/lib/ld-uClibc.so.0,该如何配置?

评论区

写评论
作者 jm-observer 2022-11-12 20:34

通过添加rustflags的参数来实现,完整的rustflags:

rustflags = ["-L", "native=./resources/mipsel_openwrt_lib"
    , "-l", "iot_mipsel_1004kc_debug"
    , "-l", "pthread"
    , "-l", "resolv"
    , "-C", "link-arg=-fPIC"
    , "-C", "link-arg=-static"
    , "-C", "link-arg=-Wl,--dynamic-linker=/lib/ld-uClibc.so.0"
]
1 共 1 条评论, 1 页