在我的项目中,我使用了一些依赖于C
库的库。当我想将应用程序放入容器中时,我已经准备好cargo
配置以静态链接所需的库。当然,我使用x86_64-unknown-linux-musl
目标来构建应用程序。
.cargo / config
[build]
rustflags = ["-C", "target-feature=-crt-static", "-C", "link-arg=-lpthread", "-C", "link-arg=-ldl", "-C", "link-arg=-lm"]
进行一些更改后,构建开始失败并显示错误:
构建日志
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-m64" "-L" "over 9 thousands libraries" "-Wl,-Bdynamic" "-lbson-1.0" "-lmongoc-1.0" "-lstdc++" "-lgcc_s" "-lc" "-lpthread" "-ldl" "-lm"
= note: /usr/bin/ld: /home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libbacktrace_sys-b282a183e15a1d1c.rlib(fileline.o): relocation R_X86_64_32 against `.rodata.__rbt_backtrace_pcinfo.str1.8' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libbacktrace_sys-b282a183e15a1d1c.rlib(posix.o): relocation R_X86_64_32 against `.rodata.__rbt_backtrace_close.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libbacktrace_sys-b282a183e15a1d1c.rlib(state.o): relocation R_X86_64_32 against `.rodata.__rbt_backtrace_create_state.str1.8' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libbacktrace_sys-b282a183e15a1d1c.rlib(elf.o): relocation R_X86_64_32 against `.rodata.elf_nodebug.str1.8' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libbacktrace_sys-b282a183e15a1d1c.rlib(alloc.o): relocation R_X86_64_32 against `.rodata.__rbt_backtrace_alloc.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libbacktrace_sys-b282a183e15a1d1c.rlib(dwarf.o): relocation R_X86_64_32 against `.rodata.dwarf_buf_error.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/rust/src/target/x86_64-unknown-linux-musl/release/deps/libbacktrace_sys-b282a183e15a1d1c.rlib(read.o): relocation R_X86_64_32 against `.rodata.__rbt_backtrace_get_view.str1.1' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
更改无关紧要(我希望),因为这是一些clear
函数和结构,没有任何新的外部依赖项或调用。
我查看了backtrace-sys
的来源,但没有发现任何问题。板条箱怎么了?
我试图将-fPIC
添加到列表rustflags
到我的.cargo/config
中,但是没有任何效果。如何根据要求重新编译项目?