通过这篇文章交叉编译rust程序【https://floatflower.me/programming/rust/cross-compile-to-mt7620-mipsel/】。结果交叉编译出错。
root@ubuntu:~/rust-openwrt# cargo build --target=mipsel-unknown-linux-musl
Compiling rust-openwrt v0.1.0 (/root/rust-openwrt)
error: linking with `mipsel-openwrt-linux-gcc` failed: exit status: 1
|
= note: "mipsel-openwrt-linux-gcc" "/root/rust-openwrt/target/mipsel-unknown-linux-musl/debug/deps/rust_openwrt-b0563cd2a4f77606.11pcjwe3kbrmvd70.rcgu.o" "/root/rust-openwrt/target/mipsel-unknown-linux-musl/debug/deps/rust_openwrt-b0563cd2a4f77606.2snnq5hx1e7b6bz7.rcgu.o" "/root/rust-openwrt/target/mipsel-unknown-linux-musl/debug/deps/rust_openwrt-b0563cd2a4f77606.30prd3h3vub54u9a.rcgu.o" "/root/rust-openwrt/target/mipsel-unknown-linux-musl/debug/deps/rust_openwrt-b0563cd2a4f77606.3cdb2bt66k216bzq.rcgu.o" "/root/rust-openwrt/target/mipsel-unknown-linux-musl/debug/deps/rust_openwrt-b0563cd2a4f77606.3z83hdh3v4utiequ.rcgu.o" "/root/rust-openwrt/target/mipsel-unknown-linux-musl/debug/deps/rust_openwrt-b0563cd2a4f77606.7qnkbzv7hcka8tv.rcgu.o" "/root/rust-openwrt/target/mipsel-unknown-linux-musl/debug/deps/rust_openwrt-b0563cd2a4f77606.946ueu4qu4k1l6x.rcgu.o" "/root/rust-openwrt/target/mipsel-unknown-linux-musl/debug/deps/rust_openwrt-b0563cd2a4f77606.iuozael5z5icr6l.rcgu.o" "/root/rust-openwrt/target/mipsel-unknown-linux-musl/debug/deps/rust_openwrt-b0563cd2a4f77606.x5eln5gqql1bkwl.rcgu.o" "-Wl,--as-needed" "-L" "/root/rust-openwrt/target/mipsel-unknown-linux-musl/debug/deps" "-L" "/root/rust-openwrt/target/debug/deps" "-L" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-0c3d17446a6389f2.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libpanic_unwind-28e0c39a7890144a.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libminiz_oxide-19d6383f5bd0456e.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libadler-b7204fba1b497efa.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libobject-b8f6da601c2ef449.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libaddr2line-7cc6c78aaea7739c.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libgimli-fbfcabe0eae9c981.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd_detect-41f5f9faa644fb50.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_demangle-6b5ea21663d71732.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libhashbrown-c315c7c01a27b8ae.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_std_workspace_alloc-406736c82527a817.rlib" "/tmp/rustcG178ki/libunwind-cf97363cdaf401d7.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcfg_if-a568ba375363d09d.rlib" "/tmp/rustcG178ki/liblibc-ccce4a6da7f77a2a.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/liballoc-7c32bda76c6a63ec.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/librustc_std_workspace_core-fe84c24148a8bf5c.rlib" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcore-99898306a007f238.rlib" "-Wl,--end-group" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libcompiler_builtins-83f3356888152672.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib" "-o" "/root/rust-openwrt/target/mipsel-unknown-linux-musl/debug/deps/rust_openwrt-b0563cd2a4f77606" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs"
/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-0c3d17446a6389f2.rlib(std-0c3d17446a6389f2.std.57b1865754aac6c3-cgu.0.rcgu.o): In function `_$LT$std..sys..unix..mutex..PthreadMutexAttr$u20$as$u20$core..ops..drop..Drop$GT$::drop::hd63d0e83f42236bb':
/rustc/35fff69d043b1c0f5c29894e7f4b0da8b039c131//library/std/src/sys/unix/mutex.rs:140: undefined reference to `pthread_mutexattr_destroy'
/rustc/35fff69d043b1c0f5c29894e7f4b0da8b039c131//library/std/src/sys/unix/mutex.rs:140: undefined reference to `pthread_mutexattr_destroy'
/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-0c3d17446a6389f2.rlib(std-0c3d17446a6389f2.std.57b1865754aac6c3-cgu.0.rcgu.o): In function `std::sys::unix::rwlock::RWLock::raw_unlock::hb0ca92a2ace1833c':
/rustc/35fff69d043b1c0f5c29894e7f4b0da8b039c131//library/std/src/sys/unix/rwlock.rs:112: undefined reference to `pthread_rwlock_unlock'
/rustc/35fff69d043b1c0f5c29894e7f4b0da8b039c131//library/std/src/sys/unix/rwlock.rs:112: undefined reference to `pthread_rwlock_unlock'
/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-0c3d17446a6389f2.rlib(std-0c3d17446a6389f2.std.57b1865754aac6c3-cgu.0.rcgu.o): In function `std::sys::unix::mutex::ReentrantMutex::try_lock::h7d3bd0dedfd35c02':
/rustc/35fff69d043b1c0f5c29894e7f4b0da8b039c131//library/std/src/sys/unix/mutex.rs:121: undefined reference to `pthread_mutex_trylock'
/rustc/35fff69d043b1c0f5c29894e7f4b0da8b039c131//library/std/src/sys/unix/mutex.rs:121: undefined reference to `pthread_mutex_trylock'
/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-0c3d17446a6389f2.rlib(std-0c3d17446a6389f2.std.57b1865754aac6c3-cgu.0.rcgu.o): In function `std::sys::unix::thread_local_key::set::h27c5f84c764d3db9':
/rustc/35fff69d043b1c0f5c29894e7f4b0da8b039c131//library/std/src/sys/unix/thread_local_key.rs:16: undefined reference to `pthread_setspecific'
/rustc/35fff69d043b1c0f5c29894e7f4b0da8b039c131//library/std/src/sys/unix/thread_local_key.rs:16: undefined reference to `pthread_setspecific'
/root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/mipsel-unknown-linux-musl/lib/libstd-0c3d17446a6389f2.rlib(std-0c3d17446a6389f2.std.57b1865754aac6c3-cgu.0.rcgu.o): In function `std::sys::unix::thread_local_key::get::h221290d75ed61022' ...
请问有交叉编译成功的吗? 如何编译的。
1
共 8 条评论, 1 页
评论区
写评论非常感谢
--
👇
ywxt: 在项目
.cargo/config
(没有后缀)中添加然后即可使用cross编译.
非常感谢!!!
--
👇
Aya0wind: 如果你是想加一个链接器参数的话,有个 -C link-arg=-xxx的参数选项,这样可以指定链接器参数,比如链接pthread。也可在项目的.cargo/config.toml里配置这个参数。具体写法查cargo文档,有个rustflags条目。
在项目
.cargo/config
(没有后缀)中添加然后即可使用cross编译.
如果你是想加一个链接器参数的话,有个 -C link-arg=-xxx的参数选项,这样可以指定链接器参数,比如链接pthread。也可在项目的.cargo/config.toml里配置这个参数。具体写法查cargo文档,有个rustflags条目。
您好,一开始是使用的cross,可以编译通过,但是编译后的程序在openwrt上运行不了。执行程序报错,not found.后来改为自己制定交叉编译工具的方式,就报上面的错误。
--
👇
ywxt: 交叉编译用cross https://github.com/rust-embedded/cross
交叉编译用cross https://github.com/rust-embedded/cross
谢谢回答, 我也是这么编译的,不知道为什么回报undefined reference to `pthread_xxx',感觉像是没有指定-lpthread. 我不清楚如何把-lpthread 传递给cargo。
--
👇
WorldLink: 你看看这个的编译参数 https://github.com/dollarkillerx/smart-dns 能在openwrt上运行
你看看这个的编译参数 https://github.com/dollarkillerx/smart-dns 能在openwrt上运行