Skip to content
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

Library path issues on fedora cross compiling for windows #46418

Closed
ssendev opened this issue Dec 1, 2017 · 3 comments
Closed

Library path issues on fedora cross compiling for windows #46418

ssendev opened this issue Dec 1, 2017 · 3 comments
Labels
A-cross Area: Cross compilation C-bug Category: This is a bug. O-linux Operating system: Linux

Comments

@ssendev
Copy link

ssendev commented Dec 1, 2017

Trying to compile Hello, world! on fedora results in

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" "-nostdlib" "-m64" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/crt2.o" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/rsbegin.o" "-L" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver0.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver1.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver10.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver11.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver12.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver13.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver14.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver15.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver2.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver3.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver4.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver5.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver6.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver7.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver8.rust-cgu.o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.printserver9.rust-cgu.o" "-o" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.exe" "/app/target/x86_64-pc-windows-gnu/debug/deps/printserver-4c9c9553ae081d85.crate.allocator.rust-cgu.o" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "/app/target/x86_64-pc-windows-gnu/debug/deps" "-L" "/app/target/debug/deps" "-L" "/home/rust/.cargo/git/checkouts/winapi-rs-a54263a8eb5d0916/70e1da8/x86_64/lib" "-L" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib" "-Wl,-Bstatic" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libstd-60d4a252bdda9250.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc_system-a05404e5e059417a.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/librand-81cbf6f1d5a19206.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libpanic_unwind-0b63e20460046692.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc-f824a78e715239af.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libstd_unicode-2abaea46f194a6e1.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libunwind-7daa32005d584d8a.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liblibc-49ff25caaa6e945f.rlib" "/app/target/x86_64-pc-windows-gnu/debug/deps/libwinapi-e1e9b0b9a817ecee.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libcore-f2bd2d524c6ace24.rlib" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libcompiler_builtins-c6139fac5e899293.rlib" "-Wl,-Bdynamic" "-l" "advapi32" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-Wl,-Bstatic" "-l" "gcc_eh" "-l" "pthread" "-Wl,-Bdynamic" "-l" "winspool" "-l" "user32" "-l" "kernel32" "-l" "msimg32" "-l" "opengl32" "-l" "gdi32" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "/home/rust/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/rsend.o"
  = note: /usr/lib/gcc/x86_64-w64-mingw32/7.2.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lpthread
          collect2: error: ld returned 1 exit status

My guess is that's related to the path on ubuntu being /usr/x86_64-w64-mingw32/lib/libpthread.a while on fedora it's /usr/x86_64-w64-mingw32/sys-root/mingw/lib/libpthread.a although running RUSTFLAGS="-L /usr/x86_64-w64-mingw32/sys-root/mingw/lib" cargo build (i also tried all subpaths) did not help either

Here is my test setup:

FROM ubuntu

RUN apt-get update && apt-get install -y \
    vim \
    curl \
    gcc \
    gcc-mingw-w64-x86-64 \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app
ENV HOME=/home/rust
RUN groupadd -r -g 1000 rust \
    && useradd --no-log-init -r -g rust -u 1000 rust \
    && mkdir -p $HOME \
    && chown rust:rust $WORKDIR $HOME
USER rust
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="$HOME/.cargo/bin:$PATH"
RUN rustup target add x86_64-pc-windows-gnu
RUN echo >>~/.cargo/config '[build]\ntarget = "x86_64-pc-windows-gnu"\n\n[target.x86_64-pc-windows-gnu]\nlinker = "x86_64-w64-mingw32-gcc"\nar = "x86_64-w64-mingw32-gcc-ar"'
FROM fedora

RUN dnf install -y \
    vim \
    gcc \
    mingw64-gcc \
  && dnf clean all

WORKDIR /app
ENV HOME=/home/rust
RUN groupadd -r -g 1000 rust \
    && useradd --no-log-init -r -g rust -u 1000 rust \
    && mkdir -p $HOME \
    && chown rust:rust $WORKDIR $HOME
USER rust
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="$HOME/.cargo/bin:$PATH"
RUN rustup target add x86_64-pc-windows-gnu
RUN echo -e >>~/.cargo/config '[build]\ntarget = "x86_64-pc-windows-gnu"\n\n[target.x86_64-pc-windows-gnu]\nlinker = "x86_64-w64-mingw32-gcc"\nar = "x86_64-w64-mingw32-gcc-ar"'
mkdir test
cd test
clippaste >Dockerfile # put above snippet in Dockerfile
docker build -t rust-test .
docker run --rm -it rust-test bash
USER=a cargo init --bin
cargo build # works with ubuntu but fails with fedora

I originally filed this here retep998/winapi-rs#527 because i thought it only happened when i added the winapi crate.

I found these similar issues #32859 #33465 #44787 but they seem not to be the same.

@pietroalbini pietroalbini added O-linux Operating system: Linux A-cross Area: Cross compilation C-bug Category: This is a bug. labels Jan 23, 2018
@lanastara
Copy link

Have you tried installing "mingw64-winpthreads-static" that solved the problem for me.

@ssendev
Copy link
Author

ssendev commented Jan 24, 2018

Thank you. It did for me too.

@ssendev ssendev closed this as completed Jan 24, 2018
@deroLub6
Copy link

/usr/bin/x86_64-w64-mingw32-ld: cannot find -lboost_program_options-mt
collect2: error: ld returned 1 exit status
please help me to solve this error..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cross Area: Cross compilation C-bug Category: This is a bug. O-linux Operating system: Linux
Projects
None yet
Development

No branches or pull requests

4 participants