Skip to content

Failed to cross-compile the example program from x86_64 Linux #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Frederick888 opened this issue Aug 27, 2015 · 13 comments · Fixed by #105
Closed

Failed to cross-compile the example program from x86_64 Linux #82

Frederick888 opened this issue Aug 27, 2015 · 13 comments · Fixed by #105

Comments

@Frederick888
Copy link

I built a Rust 1.2.0 compiler under Fedora (x86_64) which supported multiple targets including x86_64-pc-windows-gnu and arm-unknown-linux-gnueabihf and successfully compiled some simple programs.

However, I failed to cross-compile the example program from curl-rust. (I can compile the example directly under Windows, haven't tried under ARM.)

When building for x86_64-pc-windows-gnu, I got:

     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)

When building for arm-unknown-linux-gnueabihf, I got:

   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)

But I did successfully cross-compile curl-rust itself for both x86_64-pc-windows-gnu and arm-unknown-linux-gnueabihf which made it weirder.

How to fix these problems? Did I miss any configurations?

@alexcrichton
Copy link
Owner

The problem here is that you're using the right cross compiler, but you're not using the right linker. The system ld is being used to link the final binary when instead the target linker needs to be used. You can specify this to cargo via:

# .cargo/config
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"

# ... same for arm

@Frederick888
Copy link
Author

@alexcrichton I did use the correct linker. Here's my ~/.cargo/config (my project locates under ~/rust so it should work)

[target]
ar = "ar"
linker = "gcc"

[target.arm-unknown-linux-gnueabihf]
ar = "arm-linux-gnueabihf-ar"
linker = "arm-linux-gnueabihf-gcc"

[target.x86_64-pc-windows-gnu]
ar = "x86_64-w64-mingw32-ar"
linker = "x86_64-w64-mingw32-gcc"

# vim:ft=toml

And you can see lines like error: linking with x86_64-w64-mingw32-gcc failed: exit code: 1 and error: linking with arm-linux-gnueabihf-gcc failed: exit code: 1 which indicated the correct linker I was using.

@alexcrichton
Copy link
Owner

Oh right, of course, I was looking at the last line where it said ld returned 1 exit status, but I think gcc must always print that regardless of whatever linker it's running.

It could be that the code wasn't actually compiled with the right compiler, which is probably the more relevant point as I believe the build script doesn't frob CC at all. If you build for windows with CC=x86_64-w64-mingw32-gcc set as an environment variable, does it work out?

@Frederick888
Copy link
Author

@alexcrichton It seems that cargo doesn't accept these environment variables. After setting CC, I ran cargo build --release and it gave me a Linux executable instead of a Windows one.

By the way, I cross-compiled some other simple programs, e.g. the dining philosophers, and successfully ran them on Windows/ARM, so I think the cargo is behaving properly.

@alexcrichton
Copy link
Owner

Yeah Cargo won't pick up the environment variables, but curl's configure script should

@Frederick888
Copy link
Author

@alexcrichton Oh, I think you've absolutely hit the point.

After setting CC, I ran cargo build --release --verbose --target x86_64-pc-windows-gnu and the build script of curl-sys failed on checking the availability of the test program. (A Linux executable expected but a Windows one given.) So I searched the log for the configuration line, which was:

Configured with: ../configure --prefix=/usr --bindir=/usr/bin --includedir=/usr/include --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --with-gnu-as --with-gnu-ld --verbose --without-newlib --disable-multilib --disable-plugin --with-system-zlib --disable-nls --without-included-gettext --disable-win32-registry --enable-languages=c,c++,objc,obj-c++,fortran --with-default-libstdcxx-abi=c++98 --with-bugurl=http://bugzilla.redhat.com/bugzilla --with-cloog --enable-threads=posix --enable-libgomp --target=x86_64-w64-mingw32 --with-sysroot=/usr/x86_64-w64-mingw32/sys-root --with-gxx-include-dir=/usr/x86_64-w64-mingw32/sys-root/mingw/include/c++

We can see --host=x86_64-redhat-linux-gnu which is obviously wrong. So how can I pass the correct host to the build script using cargo?

@alexcrichton
Copy link
Owner

It may just be modifying this repo's build script perhaps?

@Frederick888
Copy link
Author

@alexcrichton You were right. The following simple piece of code will make it work.

62a63,71
>     if target.len() > 0 {
>         if windows && target.contains("x86_64") {
>             config_opts.push("--host x86_64-w64-mingw32".to_string());
>         } else if windows && target.contains("i686") {
>             config_opts.push("--host i686-w64-mingw32".to_string());
>         } else {
>             config_opts.push("--host ".to_string() + &target);
>         }
>     }

I successfully built and tested it this time for both x86_64-w64-mingw32 and arm-unknown-linux-gnueabihf.

However, there were another minor problem during the final linking stage for ARM. I googled it and found the solution of reversing the linking sequence of crypto and ssl which actually worked afterwards. The ssl should have been put in front of crypto.

I'm new to Rust and could you please tell me how can this be controlled?

(Here's the log)

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/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/curl_example.o" "-o" "/home/frederick/programming/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/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl-8828a61714ae0eb4.rlib" "/home/frederick/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libcurl_sys-b582fd2220a1331e.rlib" "/home/frederick/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/liburl-5247f81b4a7b5841.rlib" "/home/frederick/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libmatches-68291f81832fc22d.rlib" "/home/frederick/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/liblog-8a6aba167994951e.rlib" "/home/frederick/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/liblibz_sys-e8e1552876cd3abe.rlib" "/home/frederick/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/librustc_serialize-7ff5bfc027146194.rlib" "/home/frederick/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps/libopenssl_sys-765ddf9de3c5179c.rlib" "/home/frederick/programming/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/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release" "-L" "/home/frederick/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/deps" "-L" "/home/frederick/programming/rust/curl_example/target/arm-unknown-linux-gnueabihf/release/build/curl-sys-b582fd2220a1331e/out/lib" "-L" "/home/frederick/programming/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/programming/rust/curl_example/.rust/lib/arm-unknown-linux-gnueabihf" "-L" "/home/frederick/programming/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: /opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(s3_clnt.o): In function `ssl3_check_cert_and_algorithm':
s3_clnt.c:(.text+0x32f4): undefined reference to `X509_certificate_type'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(s3_enc.o): In function `ssl3_change_cipher_state':
s3_enc.c:(.text+0xb0): undefined reference to `COMP_CTX_free'
s3_enc.c:(.text+0xc8): undefined reference to `COMP_CTX_new'
s3_enc.c:(.text+0x1ac): undefined reference to `COMP_CTX_free'
s3_enc.c:(.text+0x1c4): undefined reference to `COMP_CTX_new'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(s3_pkt.o): In function `ssl3_do_uncompress':
s3_pkt.c:(.text+0x344): undefined reference to `COMP_expand_block'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(s3_pkt.o): In function `ssl3_do_compress':
s3_pkt.c:(.text+0x38c): undefined reference to `COMP_compress_block'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(s3_both.o): In function `ssl_cert_type':
s3_both.c:(.text+0xad4): undefined reference to `X509_certificate_type'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(t1_lib.o): In function `tls1_check_chain':
t1_lib.c:(.text+0x57dc): undefined reference to `X509_certificate_type'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(t1_enc.o): In function `tls1_change_cipher_state':
t1_enc.c:(.text+0x5d8): undefined reference to `COMP_CTX_free'
t1_enc.c:(.text+0x5f0): undefined reference to `COMP_CTX_new'
t1_enc.c:(.text+0x738): undefined reference to `COMP_CTX_free'
t1_enc.c:(.text+0x750): undefined reference to `COMP_CTX_new'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_lib.o): In function `dtls1_clear_queues':
d1_lib.c:(.text+0x90): undefined reference to `pitem_free'
d1_lib.c:(.text+0x9c): undefined reference to `pqueue_pop'
d1_lib.c:(.text+0xcc): undefined reference to `pitem_free'
d1_lib.c:(.text+0xd8): undefined reference to `pqueue_pop'
d1_lib.c:(.text+0xf4): undefined reference to `pitem_free'
d1_lib.c:(.text+0x100): undefined reference to `pqueue_pop'
d1_lib.c:(.text+0x11c): undefined reference to `pitem_free'
d1_lib.c:(.text+0x128): undefined reference to `pqueue_pop'
d1_lib.c:(.text+0x158): undefined reference to `pitem_free'
d1_lib.c:(.text+0x164): undefined reference to `pqueue_pop'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_lib.o): In function `dtls1_new':
d1_lib.c:(.text+0x1bc): undefined reference to `pqueue_new'
d1_lib.c:(.text+0x1c4): undefined reference to `pqueue_new'
d1_lib.c:(.text+0x1cc): undefined reference to `pqueue_new'
d1_lib.c:(.text+0x1d4): undefined reference to `pqueue_new'
d1_lib.c:(.text+0x1dc): undefined reference to `pqueue_new'
d1_lib.c:(.text+0x238): undefined reference to `pqueue_free'
d1_lib.c:(.text+0x248): undefined reference to `pqueue_free'
d1_lib.c:(.text+0x258): undefined reference to `pqueue_free'
d1_lib.c:(.text+0x268): undefined reference to `pqueue_free'
d1_lib.c:(.text+0x278): undefined reference to `pqueue_free'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_lib.o):d1_lib.c:(.text+0x2d0): more undefined references to `pqueue_free' follow
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_pkt.o): In function `dtls1_retrieve_buffered_record':
d1_pkt.c:(.text+0x18c): undefined reference to `pqueue_pop'
d1_pkt.c:(.text+0x1b0): undefined reference to `pitem_free'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_pkt.o): In function `dtls1_buffer_record':
d1_pkt.c:(.text+0x1dc): undefined reference to `pqueue_size'
d1_pkt.c:(.text+0x208): undefined reference to `pitem_new'
d1_pkt.c:(.text+0x238): undefined reference to `pitem_free'
d1_pkt.c:(.text+0x320): undefined reference to `pitem_free'
d1_pkt.c:(.text+0x334): undefined reference to `pqueue_insert'
d1_pkt.c:(.text+0x37c): undefined reference to `pitem_free'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_pkt.o): In function `dtls1_get_record':
d1_pkt.c:(.text+0x690): undefined reference to `pqueue_peek'
d1_pkt.c:(.text+0x704): undefined reference to `pqueue_peek'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_pkt.o): In function `dtls1_read_bytes':
d1_pkt.c:(.text+0x12d8): undefined reference to `pqueue_pop'
d1_pkt.c:(.text+0x12fc): undefined reference to `pitem_free'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_both.o): In function `dtls1_reassemble_fragment':
d1_both.c:(.text+0x2e4): undefined reference to `pqueue_find'
d1_both.c:(.text+0x534): undefined reference to `pitem_new'
d1_both.c:(.text+0x54c): undefined reference to `pqueue_insert'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_both.o): In function `dtls1_buffer_message':
d1_both.c:(.text+0x7ec): undefined reference to `pitem_new'
d1_both.c:(.text+0x810): undefined reference to `pqueue_insert'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_both.o): In function `dtls1_clear_record_buffer':
d1_both.c:(.text+0x850): undefined reference to `pqueue_pop'
d1_both.c:(.text+0x868): undefined reference to `pitem_free'
d1_both.c:(.text+0x874): undefined reference to `pqueue_pop'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_both.o): In function `dtls1_retransmit_message':
d1_both.c:(.text+0x101c): undefined reference to `pqueue_find'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_both.o): In function `dtls1_retransmit_buffered_messages':
d1_both.c:(.text+0x121c): undefined reference to `pqueue_iterator'
d1_both.c:(.text+0x122c): undefined reference to `pqueue_next'
d1_both.c:(.text+0x129c): undefined reference to `pqueue_next'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(d1_both.o): In function `dtls1_get_message':
d1_both.c:(.text+0x1420): undefined reference to `pqueue_peek'
d1_both.c:(.text+0x1460): undefined reference to `pqueue_pop'
d1_both.c:(.text+0x14a8): undefined reference to `pitem_free'
d1_both.c:(.text+0x15e8): undefined reference to `pqueue_find'
d1_both.c:(.text+0x173c): undefined reference to `pitem_new'
d1_both.c:(.text+0x1750): undefined reference to `pqueue_insert'
d1_both.c:(.text+0x1aac): undefined reference to `pitem_free'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(ssl_lib.o): In function `SSL_set_fd':
ssl_lib.c:(.text+0x574): undefined reference to `BIO_s_socket'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(ssl_lib.o): In function `SSL_set_wfd':
ssl_lib.c:(.text+0x628): undefined reference to `BIO_s_socket'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(ssl_lib.o): In function `SSL_set_rfd':
ssl_lib.c:(.text+0x6f8): undefined reference to `BIO_s_socket'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(ssl_lib.o): In function `ssl_clear_cipher_ctx':
ssl_lib.c:(.text+0x3254): undefined reference to `COMP_CTX_free'
ssl_lib.c:(.text+0x326c): undefined reference to `COMP_CTX_free'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(ssl_lib.o): In function `SSL_CTX_set_default_verify_paths':
ssl_lib.c:(.text+0x35e4): undefined reference to `X509_STORE_set_default_paths'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(ssl_lib.o): In function `SSL_CTX_load_verify_locations':
ssl_lib.c:(.text+0x35f4): undefined reference to `X509_STORE_load_locations'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(ssl_err2.o): In function `SSL_load_error_strings':
ssl_err2.c:(.text+0x4): undefined reference to `ERR_load_crypto_strings'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(ssl_cert.o): In function `SSL_add_dir_cert_subjects_to_stack':
ssl_cert.c:(.text+0x1448): undefined reference to `OPENSSL_DIR_read'
ssl_cert.c:(.text+0x14d0): undefined reference to `OPENSSL_DIR_end'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(ssl_ciph.o): In function `load_builtin_compressions':
ssl_ciph.c:(.text+0x44c): undefined reference to `COMP_zlib'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(ssl_ciph.o): In function `ssl_cipher_get_evp':
ssl_ciph.c:(.text+0xe78): undefined reference to `EVP_enc_null'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(tls_srp.o): In function `SSL_srp_server_param_with_username':
tls_srp.c:(.text+0x4b4): undefined reference to `SRP_Calc_B'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(tls_srp.o): In function `SSL_set_srp_server_param_pw':
tls_srp.c:(.text+0x4ec): undefined reference to `SRP_get_default_gN'
tls_srp.c:(.text+0x560): undefined reference to `SRP_create_verifier_BN'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(tls_srp.o): In function `SRP_generate_server_master_secret':
tls_srp.c:(.text+0x710): undefined reference to `SRP_Verify_A_mod_N'
tls_srp.c:(.text+0x728): undefined reference to `SRP_Calc_u'
tls_srp.c:(.text+0x74c): undefined reference to `SRP_Calc_server_key'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(tls_srp.o): In function `SRP_generate_client_master_secret':
tls_srp.c:(.text+0x820): undefined reference to `SRP_Verify_B_mod_N'
tls_srp.c:(.text+0x838): undefined reference to `SRP_Calc_u'
tls_srp.c:(.text+0x870): undefined reference to `SRP_Calc_x'
tls_srp.c:(.text+0x898): undefined reference to `SRP_Calc_client_key'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(tls_srp.o): In function `srp_verify_server_param':
tls_srp.c:(.text+0xa48): undefined reference to `SRP_check_known_gN_param'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(tls_srp.o): In function `SRP_Calc_A_param':
tls_srp.c:(.text+0xabc): undefined reference to `SRP_Calc_A'
/opt/crosstool-ng-tools/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib/libssl.a(s3_srvr.o): In function `ssl3_get_cert_verify':
s3_srvr.c:(.text+0x3208): undefined reference to `X509_certificate_type'
collect2: error: ld returned 1 exit status

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

@alexcrichton
Copy link
Owner

Ah swapping the order looks like it'd just be useful in general, so I submitted a PR to rust-openssl

@Frederick888
Copy link
Author

@alexcrichton Thanks a lot. And please include my patch in the next release of curl-rust

@alexcrichton
Copy link
Owner

@Frederick888 ah sorry I think I may have lost precisely what the patch was in the log here, would you be ok submitting a PR?

@Frederick888
Copy link
Author

@alexcrichton Of course. #83

@OluAgunloye
Copy link

anyone able to help with a similar curl issue I'm having?

I obtain undefined reference errors as well when compiling code that should have already statically linked curl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants