1

使用 Cargo 构建项目时收到以下错误消息:

error: linking with `gcc` failed: exit code: 1
note: gcc '-Wl,--enable-long-section-names' '-fno-use-linker-plugin' '-Wl,--nxcompat' '-static-libgcc' '-m64' '-L' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib' '-o' 'D:\__start\rust-iron\target\rust-iron.exe' 'D:\__start\rust-iron\target\rust-iron.o' '-Wl,--gc-sections' 'D:\__start\rust-iron\target\deps\libiron-bc16133d0a47ffb0.rlib' 'D:\__start\rust-iron\target\deps\libhyper-f94dbe5abc871209.rlib' 'D:\__start\rust-iron\target\deps\libmodifier-1f4dc100e0edbf7d.rlib' 'D:\__start\rust-iron\target\deps\libmucell-ac2514f1ba9841c5.rlib' 'D:\__start\rust-iron\target\deps\libplugin-3af9d50d18e9bee7.rlib' 'D:\__start\rust-iron\target\deps\libmime-115ca8125c42dc12.rlib' 'D:\__start\rust-iron\target\deps\liberror-e47fda06a095ed9c.rlib' 'D:\__start\rust-iron\target\deps\libtypeable-175afcd94f146dcc.rlib' 'D:\__start\rust-iron\target\deps\libphantom-cd9583ecf037f4d7.rlib' 'D:\__start\rust-iron\target\deps\liblog-4e79c2d7625e8c6f.rlib' 'D:\__start\rust-iron\target\deps\libcookie-4a08a2c06bb5c4fc.rlib' 'D:\__start\rust-iron\target\deps\liburl-4c384fb33b0bde93.rlib' 'D:\__start\rust-iron\target\deps\librustc-serialize-8214bc2e838e96ca.rlib' 'D:\__start\rust-iron\target\deps\libopenssl-9e47789a605aabbf.rlib' 'D:\__start\rust-iron\target\deps\libtime-24f9c2dbbbc6f19b.rlib' 'D:\__start\rust-iron\target\deps\libmatches-68db25b520030534.rlib' 'D:\__start\rust-iron\target\deps\libopenssl-sys-f6d7192b17104bf7.rlib' 'D:\__start\rust-iron\target\deps\libtypemap-add7a21f97d0ca71.rlib' 'D:\__start\rust-iron\target\deps\libunsafe-any-3f018797a3613438.rlib' 'D:\__start\rust-iron\target\deps\libunicase-88de2458e97b894d.rlib' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\libstd-4e7c5e5c.rlib' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\libcollections-4e7c5e5c.rlib' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\libunicode-4e7c5e5c.rlib' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\librand-4e7c5e5c.rlib' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\liballoc-4e7c5e5c.rlib' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\liblibc-4e7c5e5c.rlib' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib\libcore-4e7c5e5c.rlib' '-L' 'D:\__start\rust-iron\target' '-L' 'D:\__start\rust-iron\target\deps' '-L' '\opt\windows_64\lib64' '-L' 'D:\__start\rust-iron\target\build\time-24f9c2dbbbc6f19b\out' '-L' 'C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib' '-L' 'D:\__start\rust-iron\.rust\bin\x86_64-pc-windows-gnu' '-L' 'D:\__start\rust-iron\bin\x86_64-pc-windows-gnu' '-Wl,--whole-archive' '-Wl,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-lssl' '-lcrypto' '-lws2_32' '-lcompiler-rt'
note: C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x59): undefined reference to `inflate'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0xea): undefined reference to `deflate'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x13d): undefined reference to `inflateEnd'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x158): undefined reference to `deflateEnd'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x1c3): undefined reference to `inflateEnd'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x1cc): undefined reference to `deflateEnd'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x267): undefined reference to `inflateInit_'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x2dd): undefined reference to `deflateInit_'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x545): undefined reference to `deflate'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x5ff): undefined reference to `zError'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x7f0): undefined reference to `deflate'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x8b1): undefined reference to `zError'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x911): undefined reference to `deflateInit_'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0x9e0): undefined reference to `inflate'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0xa4f): undefined reference to `zError'
C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o):c_zlib.c:(.text+0xac4): undefined reference to `inflateInit_'
ld: C:\Rust\bin\rustlib\x86_64-pc-windows-gnu\lib/libcrypto.a(c_zlib.o): bad reloc address 0x8 in section `.data'

error: aborting due to previous error

我已经读到我可能可以添加-lz标志来防止这种情况,但是我该如何使用 Cargo 来做到这一点?

4

1 回答 1

0

构建脚本

将行添加build = "build.rs"到您的Cargo.toml然后将其写入build.rs

fn main() {
    println!("cargo:rustc-flags=-lz");
}

理论上会将该标志添加到您的编译参数中

于 2015-02-11T20:55:54.540 回答