链接Rust项目:“制作PIE对象时无法使用;请使用-fPIC重新编译”

时间:2019-11-29 14:00:00

标签: compilation rust rust-cargo cc rust-crates

在我的项目中,我使用了一些依赖于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中,但是没有任何效果。如何根据要求重新编译项目?

0 个答案:

没有答案