rust-lang / libc

Raw bindings to platform APIs for Rust
https://docs.rs/libc
Apache License 2.0
2.08k stars 1.04k forks source link

Linking fails on 64-bit Windows using 32-bit Rust #8

Closed Boddlnagg closed 9 years ago

Boddlnagg commented 9 years ago

I'm on 64-bit Windows, but using 32-bit Rust nightly (rustc 1.1.0-nightly (0d7d3ec9d 2015-05-02) (built 2015-05-03)), because I need a 32-bit target binary.

Trying to compile a library [*] that references libc (via Cargo depency) gives the following linking error:

error: linking with `gcc` failed: exit code: 1
note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nx
compat" "-Wl,--large-address-aware" "-shared-libgcc" "-L" "C:\Program Files (x86
)\Rust nightly 1.1\bin\rustlib\i686-pc-windows-gnu\lib" "-o" "C:\Users\Patrick\D
ocuments\Rust\testlibc\target\debug\testlibc-c7065bc1f5bc856b.exe" "C:\Users\Pat
rick\Documents\Rust\testlibc\target\debug\testlibc-c7065bc1f5bc856b.o" "-Wl,--gc
-sections" "C:\Program Files (x86)\Rust nightly 1.1\bin\rustlib\i686-pc-windows-
gnu\lib\libtest-4e7c5e5c.rlib" "C:\Program Files (x86)\Rust nightly 1.1\bin\rust
lib\i686-pc-windows-gnu\lib\libserialize-4e7c5e5c.rlib" "C:\Program Files (x86)\
Rust nightly 1.1\bin\rustlib\i686-pc-windows-gnu\lib\libterm-4e7c5e5c.rlib" "C:\
Program Files (x86)\Rust nightly 1.1\bin\rustlib\i686-pc-windows-gnu\lib\liblog-
4e7c5e5c.rlib" "C:\Program Files (x86)\Rust nightly 1.1\bin\rustlib\i686-pc-wind
ows-gnu\lib\libgetopts-4e7c5e5c.rlib" "C:\Program Files (x86)\Rust nightly 1.1\b
in\rustlib\i686-pc-windows-gnu\lib\libstd-4e7c5e5c.rlib" "C:\Program Files (x86)
\Rust nightly 1.1\bin\rustlib\i686-pc-windows-gnu\lib\libcollections-4e7c5e5c.rl
ib" "C:\Program Files (x86)\Rust nightly 1.1\bin\rustlib\i686-pc-windows-gnu\lib
\librustc_unicode-4e7c5e5c.rlib" "C:\Program Files (x86)\Rust nightly 1.1\bin\ru
stlib\i686-pc-windows-gnu\lib\librand-4e7c5e5c.rlib" "C:\Program Files (x86)\Rus
t nightly 1.1\bin\rustlib\i686-pc-windows-gnu\lib\liballoc-4e7c5e5c.rlib" "C:\Pr
ogram Files (x86)\Rust nightly 1.1\bin\rustlib\i686-pc-windows-gnu\lib\liblibc-4
e7c5e5c.rlib" "C:\Program Files (x86)\Rust nightly 1.1\bin\rustlib\i686-pc-windo
ws-gnu\lib\libcore-4e7c5e5c.rlib" "-L" "C:\Users\Patrick\Documents\Rust\testlibc
\target\debug" "-L" "C:\Users\Patrick\Documents\Rust\testlibc\target\debug\deps"
 "-L" "\\?\C:\Program Files (x86)\Rust nightly 1.1\bin\rustlib\i686-pc-windows-g
nu\lib" "-L" "C:\Users\Patrick\Documents\Rust\testlibc\.rust\bin\i686-pc-windows
-gnu" "-L" "C:\Users\Patrick\Documents\Rust\testlibc\bin\i686-pc-windows-gnu" "-
Wl,--whole-archive" "-Wl,-Bstatic" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-lk
ernel32" "-lws2_32" "-luserenv" "-lcompiler-rt"
note: ld: cannot find crt2.o: No such file or directory
ld: cannot find crtbegin.o: No such file or directory
ld: cannot find crtend.o: No such file or directory

It seems to reference the correct files in C:\Program Files (x86)\Rust nightly 1.1\bin\rustlib\i686-pc-windows-gnu\lib\, and I verified that crt2.o etc are in there.

Also, I have 64-bit Rust installed in parallel (in C:\Program Files\Rust nightly 1.1), might that be the reason?

[*] I could reduce it to an empty library, though the error originally occured when I tried to use user32-sys from https://github.com/retep998/winapi-rs

Boddlnagg commented 9 years ago

I've just seen that this is not specific to libc but has been reported here: https://github.com/rust-lang/rust/issues/25072 Therefore this issue may be closed.

alexcrichton commented 9 years ago

Closing in favor of the linked issue, thanks for the report!