gpt4 book ai didi

gcc - 无法交叉编译 curl-rust 示例

转载 作者:行者123 更新时间:2023-11-29 08:01:08 26 4
gpt4 key购买 nike

我在 Fedora (x86_64) 下构建了一个 Rust 1.2.0 交叉编译器,它支持多个目标,包括 x86_64-pc-windows-gnuarm-unknown-linux-gnueabihf 并成功编译了一些简单的程序。

但是,我未能交叉编译来自curl-rust 的示例程序.

在为 x86_64-pc-windows-gnu 构建时,我得到:

     Compiling curl_example v0.1.0 (file:///home/frederick/rust/curl_example)
Running `rustc src/main.rs --crate-name curl_example --crate-type bin -C opt-level=3 --out-dir /home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release --emit=dep-info,link --target x86_64-pc-windows-gnu -C ar=x86_64-w64-mingw32-ar -C linker=x86_64-w64-mingw32-gcc -L dependency=/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release -L dependency=/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps --extern curl=/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps/libcurl-8828a61714ae0eb4.rlib -L /home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/build/curl-sys-b582fd2220a1331e/out/lib`
error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
note: "x86_64-w64-mingw32-gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-static-libgcc" "-m64" "-L" "/usr/local/lib/rustlib/x86_64-pc-windows-gnu/lib" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/curl_example.o" "-o" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/curl_example.exe" "-Wl,--gc-sections" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps/libcurl-8828a61714ae0eb4.rlib" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps/libcurl_sys-b582fd2220a1331e.rlib" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps/liburl-5247f81b4a7b5841.rlib" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps/libmatches-68291f81832fc22d.rlib" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps/liblog-8a6aba167994951e.rlib" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps/liblibz_sys-e8e1552876cd3abe.rlib" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps/liblibc-144c435538abd757.rlib" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps/librustc_serialize-7ff5bfc027146194.rlib" "/usr/local/lib/rustlib/x86_64-pc-windows-gnu/lib/libstd-d8ace771.rlib" "/usr/local/lib/rustlib/x86_64-pc-windows-gnu/lib/libcollections-d8ace771.rlib" "/usr/local/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc_unicode-d8ace771.rlib" "/usr/local/lib/rustlib/x86_64-pc-windows-gnu/lib/librand-d8ace771.rlib" "/usr/local/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc-d8ace771.rlib" "/usr/local/lib/rustlib/x86_64-pc-windows-gnu/lib/liblibc-d8ace771.rlib" "/usr/local/lib/rustlib/x86_64-pc-windows-gnu/lib/libcore-d8ace771.rlib" "-L" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release" "-L" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps" "-L" "/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/build/curl-sys-b582fd2220a1331e/out/lib" "-L" "/usr/local/lib/rustlib/x86_64-pc-windows-gnu/lib" "-L" "/home/frederick/rust/curl_example/.rust/lib/x86_64-pc-windows-gnu" "-L" "/home/frederick/rust/curl_example/lib/x86_64-pc-windows-gnu" "-Wl,-Bstatic" "-Wl,-Bdynamic" "-l" "ws2_32" "-l" "z" "-l" "ws2_32" "-l" "userenv" "-l" "advapi32" "-l" "compiler-rt"
note: /home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps/libcurl_sys-b582fd2220a1331e.rlib(r-curl-libcurl_la-version.o): could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status

error: aborting due to previous error
Could not compile `curl_example`.

Caused by:
Process didn't exit successfully: `rustc src/main.rs --crate-name curl_example --crate-type bin -C opt-level=3 --out-dir /home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release --emit=dep-info,link --target x86_64-pc-windows-gnu -C ar=x86_64-w64-mingw32-ar -C linker=x86_64-w64-mingw32-gcc -L dependency=/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release -L dependency=/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps --extern curl=/home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/deps/libcurl-8828a61714ae0eb4.rlib -L /home/frederick/rust/curl_example/target/x86_64-pc-windows-gnu/release/build/curl-sys-b582fd2220a1331e/out/lib` (exit code: 101)

在为 arm-unknown-linux-gnueabihf 构建时,我得到:

   Compiling curl_example v0.1.0 (file:///home/frederick/rust/curl_example)
Running `rustc src/main.rs --crate-name curl_example --crate-type bin -C opt-level=3 --out-dir /home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release --emit=dep-info,link --target arm-unknown-linux-gnueabihf -C ar=arm-linux-gnueabihf-ar -C linker=arm-linux-gnueabihf-gcc -L dependency=/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release -L dependency=/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps --extern curl=/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib -L /home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/build/curl-sys-b582fd2220a1331e/out/lib -L native=/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/build/openssl-sys-765ddf9de3c5179c/out`
error: linking with `arm-linux-gnueabihf-gcc` failed: exit code: 1
note: "arm-linux-gnueabihf-gcc" "-Wl,--as-needed" "-L" "/usr/local/lib/rustlib/arm-unknown-linux-gnueabihf/lib" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/curl_example.o" "-o" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/curl_example" "-Wl,--whole-archive" "-l" "morestack" "-Wl,--no-whole-archive" "-Wl,--gc-sections" "-pie" "-Wl,-O1" "-nodefaultlibs" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl_sys-b582fd2220a1331e.rlib" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/liburl-5247f81b4a7b5841.rlib" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libmatches-68291f81832fc22d.rlib" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/liblog-8a6aba167994951e.rlib" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/liblibz_sys-e8e1552876cd3abe.rlib" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/librustc_serialize-7ff5bfc027146194.rlib" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libopenssl_sys-765ddf9de3c5179c.rlib" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/liblibc-144c435538abd757.rlib" "/usr/local/lib/rustlib/arm-unknown-linux-gnueabihf/lib/libstd-d8ace771.rlib" "/usr/local/lib/rustlib/arm-unknown-linux-gnueabihf/lib/libcollections-d8ace771.rlib" "/usr/local/lib/rustlib/arm-unknown-linux-gnueabihf/lib/librustc_unicode-d8ace771.rlib" "/usr/local/lib/rustlib/arm-unknown-linux-gnueabihf/lib/librand-d8ace771.rlib" "/usr/local/lib/rustlib/arm-unknown-linux-gnueabihf/lib/liballoc-d8ace771.rlib" "/usr/local/lib/rustlib/arm-unknown-linux-gnueabihf/lib/liblibc-d8ace771.rlib" "/usr/local/lib/rustlib/arm-unknown-linux-gnueabihf/lib/libcore-d8ace771.rlib" "-L" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release" "-L" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps" "-L" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/build/curl-sys-b582fd2220a1331e/out/lib" "-L" "/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/build/openssl-sys-765ddf9de3c5179c/out" "-L" "/usr/local/lib/rustlib/arm-unknown-linux-gnueabihf/lib" "-L" "/home/frederick/rust/curl_example/.rust/lib/arm-unknown-linux-gnueabihf" "-L" "/home/frederick/rust/curl_example/lib/arm-unknown-linux-gnueabihf" "-Wl,-Bstatic" "-Wl,-Bdynamic" "-l" "z" "-l" "crypto" "-l" "ssl" "-l" "c" "-l" "m" "-l" "dl" "-l" "pthread" "-l" "rt" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "compiler-rt"
note: /home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/curl_example.o: In function `main::h3f0c65dd085aa280gaa':
curl_example.0.rs:(.text._ZN4main20h3f0c65dd085aa280gaaE+0x188): undefined reference to `curl_easy_setopt'
/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib(curl-8828a61714ae0eb4.o): In function `ffi::easy::global_init::cleanup::hfb9c781cea2b575dzia':
curl.0.rs:(.text._ZN3ffi4easy11global_init7cleanup20hfb9c781cea2b575dziaE+0x0): undefined reference to `curl_global_cleanup'
/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib(curl-8828a61714ae0eb4.o): In function `ffi::easy::Easy.Drop::drop::h0c646593d425c9d3Hia':
curl.0.rs:(.text._ZN3ffi4easy9Easy.Drop4drop20h0c646593d425c9d3HiaE+0x4): undefined reference to `curl_easy_cleanup'
/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib(curl-8828a61714ae0eb4.o): In function `ffi::err::ErrCode.fmt..Display::fmt::h032b81c4990a5e2fOra':
curl.0.rs:(.text._ZN3ffi3err20ErrCode.fmt..Display3fmt20h032b81c4990a5e2fOraE+0x48): undefined reference to `curl_easy_strerror'
/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib(curl-8828a61714ae0eb4.o): In function `http::handle::Handle::new::hcbd4647fea69f7fe3Va':
curl.0.rs:(.text._ZN4http6handle6Handle3new20hcbd4647fea69f7fe3VaE+0x220): undefined reference to `curl_easy_init'
curl.0.rs:(.text._ZN4http6handle6Handle3new20hcbd4647fea69f7fe3VaE+0x230): undefined reference to `curl_easy_setopt'
curl.0.rs:(.text._ZN4http6handle6Handle3new20hcbd4647fea69f7fe3VaE+0x244): undefined reference to `curl_easy_setopt'
curl.0.rs:(.text._ZN4http6handle6Handle3new20hcbd4647fea69f7fe3VaE+0x260): undefined reference to `curl_easy_setopt'
curl.0.rs:(.text._ZN4http6handle6Handle3new20hcbd4647fea69f7fe3VaE+0x49c): undefined reference to `curl_easy_cleanup'
curl.0.rs:(.text._ZN4http6handle6Handle3new20hcbd4647fea69f7fe3VaE+0x534): undefined reference to `curl_easy_cleanup'
curl.0.rs:(.text._ZN4http6handle6Handle3new20hcbd4647fea69f7fe3VaE+0x558): undefined reference to `curl_easy_cleanup'
curl.0.rs:(.text._ZN4http6handle6Handle3new20hcbd4647fea69f7fe3VaE+0x5dc): undefined reference to `curl_easy_cleanup'
/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib(curl-8828a61714ae0eb4.o): In function `ffi::easy::Easy::setopt::h17415893674049649907':
curl.0.rs:(.text._ZN3ffi4easy4Easy6setopt21h17415893674049649907E+0x1bc): undefined reference to `curl_easy_setopt'
/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib(curl-8828a61714ae0eb4.o): In function `http::handle::Request$LT$$u27$a$C$$u20$$u27$b$GT$::exec::hd3fad3894ea8584cgab':
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0x108): undefined reference to `curl_easy_setopt'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0x14c): undefined reference to `curl_easy_setopt'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0x1a0): undefined reference to `curl_easy_setopt'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0x1b8): undefined reference to `curl_easy_setopt'
/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib(curl-8828a61714ae0eb4.o):curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0x1d0): more undefined references to `curl_easy_setopt' follow
/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib(curl-8828a61714ae0eb4.o): In function `http::handle::Request$LT$$u27$a$C$$u20$$u27$b$GT$::exec::hd3fad3894ea8584cgab':
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0x8e4): undefined reference to `curl_slist_append'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0x94c): undefined reference to `curl_easy_setopt'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0x998): undefined reference to `curl_slist_free_all'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0xa30): undefined reference to `curl_easy_setopt'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0xa50): undefined reference to `curl_easy_setopt'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0xa70): undefined reference to `curl_easy_setopt'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0xa84): undefined reference to `curl_easy_setopt'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0xaa4): undefined reference to `curl_easy_setopt'
/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib(curl-8828a61714ae0eb4.o):curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0xabc): more undefined references to `curl_easy_setopt' follow
/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib(curl-8828a61714ae0eb4.o): In function `http::handle::Request$LT$$u27$a$C$$u20$$u27$b$GT$::exec::hd3fad3894ea8584cgab':
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0xaf8): undefined reference to `curl_easy_perform'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0xb30): undefined reference to `curl_easy_getinfo'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0xc0c): undefined reference to `curl_slist_free_all'
curl.0.rs:(.text._ZN4http6handle35Request$LT$$u27$a$C$$u20$$u27$b$GT$4exec20hd3fad3894ea8584cgabE+0xe24): undefined reference to `curl_slist_free_all'
/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib(curl-8828a61714ae0eb4.o): In function `ffi::easy::Easy::setopt::h1335928551378549339':
curl.0.rs:(.text._ZN3ffi4easy4Easy6setopt20h1335928551378549339E+0x160): undefined reference to `curl_easy_setopt'
collect2: error: ld returned 1 exit status

error: aborting due to previous error
Could not compile `curl_example`.

Caused by:
Process didn't exit successfully: `rustc src/main.rs --crate-name curl_example --crate-type bin -C opt-level=3 --out-dir /home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release --emit=dep-info,link --target arm-unknown-linux-gnueabihf -C ar=arm-linux-gnueabihf-ar -C linker=arm-linux-gnueabihf-gcc -L dependency=/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release -L dependency=/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps --extern curl=/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib -L /home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/build/curl-sys-b582fd2220a1331e/out/lib -L native=/home/frederick/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/build/openssl-sys-765ddf9de3c5179c/out` (exit code: 101)

但我确实成功地为 x86_64-pc-windows-gnuarm-unknown-linux-gnueabihf 交叉编译了 curl-rust 本身> 这让它变得更奇怪了。

如何解决这些问题?我是否遗漏了任何配置?

最佳答案

问题的主要原因是构建脚本没有将host传递给curl的配置命令。我已经发送了 PR给作者一个discussion之后.所以等待更新或只在本地应用补丁。

但实际上还有另一个问题可能会在最后的链接阶段编译失败。 ssl 应该在 crypto 之前链接,但是 rust-openssl 是以相反的顺序进行的。 curl-rust 的作者已向 rust-openssl 项目发送了 PR。

关于gcc - 无法交叉编译 curl-rust 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32235620/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com