Skip to content

Link error for x86_64-pc-windows-gnu #362

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
zonyitoo opened this issue Jan 7, 2020 · 5 comments
Closed

Link error for x86_64-pc-windows-gnu #362

zonyitoo opened this issue Jan 7, 2020 · 5 comments

Comments

@zonyitoo
Copy link

zonyitoo commented Jan 7, 2020

* Building x86_64-pc-windows-gnu package 1.8.2 ...
   Compiling shadowsocks-rust v1.8.2 (/project)
error: linking with `gcc` failed: exit code: 1
  |
  = note: "gcc" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/crt2.o" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/rsbegin.o" "-L" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib" "/target/x86_64-pc-windows-gnu/release/deps/ssurl-28e42ab8516f5980.ssurl.7wvvpq37-cgu.1.rcgu.o" "-o" "/target/x86_64-pc-windows-gnu/release/deps/ssurl-28e42ab8516f5980.exe" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "/target/x86_64-pc-windows-gnu/release/deps" "-L" "/target/release/deps" "-L" "/cargo/registry/src/github.com-1ecc6299db9ec823/winapi-x86_64-pc-windows-gnu-0.4.0/lib" "-L" "/usr/x86_64-w64-mingw32/lib" "-L" "/usr/x86_64-w64-mingw32/lib" "-L" "/target/x86_64-pc-windows-gnu/release/build/ring-111ba8649af88a7c/out" "-L" "/target/x86_64-pc-windows-gnu/release/build/backtrace-sys-c62025733561b702/out" "-L" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib" "-Wl,-Bstatic" "/tmp/rustcpZ7ap9/liblibsodium_sys-e1f382851cf88836.rlib" "/tmp/rustcpZ7ap9/libopenssl_sys-9653330b16ffda9c.rlib" "/tmp/rustcpZ7ap9/libring-6093be3c65bfd4e9.rlib" "/tmp/rustcpZ7ap9/libbacktrace_sys-f8f2b1afe0245f37.rlib" "-Wl,--start-group" "/tmp/rustcpZ7ap9/libbacktrace_sys-e1f0d80e45647562.rlib" "-Wl,--end-group" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libcompiler_builtins-960a85ac60917763.rlib" "-Wl,-Bdynamic" "-lgdi32" "-luser32" "-lcrypt32" "-lws2_32" "-ladvapi32" "-ladvapi32" "-lws2_32" "-lkernel32" "-liphlpapi" "-lwinapi_advapi32" "-lwinapi_cfgmgr32" "-lwinapi_credui" "-lwinapi_fwpuclnt" "-lwinapi_gdi32" "-lwinapi_kernel32" "-lwinapi_msimg32" "-lwinapi_mswsock" "-lwinapi_ntdll" "-lwinapi_opengl32" "-lwinapi_secur32" "-lwinapi_synchronization" "-lwinapi_user32" "-lwinapi_winspool" "-lwinapi_ws2_32" "-ladvapi32" "-lws2_32" "-luserenv" "-Wl,-Bstatic" "-lgcc_eh" "-lpthread" "-Wl,-Bdynamic" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-lmsvcrt" "-luser32" "-lkernel32" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/rsend.o"
  = note: /usr/bin/ld: unrecognized option '--nxcompat'
          /usr/bin/ld: use the --help option for usage information
          collect2: error: ld returned 1 exit status

It seems that cargo is using the wrong linker (x86_64-w64-mingw32-gcc instead of gcc).

Build script: https://github.com/shadowsocks/shadowsocks-rust/blob/master/build/build-release#L17-L19

Dockerfile: https://github.com/shadowsocks/shadowsocks-rust/blob/master/build/Dockerfile.x86_64-pc-windows-gnu

@zonyitoo
Copy link
Author

zonyitoo commented Jan 8, 2020

It seems that CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER is ignored.

@zonyitoo
Copy link
Author

zonyitoo commented Jan 8, 2020

Related: rust-lang/cargo#7763

@zonyitoo zonyitoo closed this as completed Jan 8, 2020
@BurntSushi
Copy link

@zonyitoo How did you end up fixing this? I'm using the 2020-01-15 nightly, but still getting the same error.

@zonyitoo
Copy link
Author

I fixed it just by updating rustc to the "latest" nightly.

cross 0.1.16
cargo 1.42.0-nightly (6e1ca924a 2020-01-06)

@BurntSushi
Copy link

Yeah, I am on the latest nightly.

Turns out the problem was between the chair and the keyboard. I was running cross t --target ... and t is treated as an "other" sub-command that is passed through to Cargo without running docker. But it wasn't at all clear that that was what was happening. So I ended up with weird linker errors. Using cross test --target ... fixed it for me.

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

No branches or pull requests

3 participants