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

Cross-compiling fails with gcc-rs #4456

Closed
dm0- opened this issue Sep 1, 2017 · 6 comments
Closed

Cross-compiling fails with gcc-rs #4456

dm0- opened this issue Sep 1, 2017 · 6 comments
Labels
A-environment-variables Area: environment variables A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-bug Category: bug

Comments

@dm0-
Copy link

dm0- commented Sep 1, 2017

I am unable to cross-compile via cargo build --target when projects use gcc-rs if the host binutils has libraries in /usr/lib and the cross-binutils libraries are elsewhere. It causes the cross-compiler programs to use the host libraries with bad results. Here is an example failure message:

running: "aarch64-pc-linux-gnu-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-o" ".../target/aarch64-unknown-linux-gnu/debug/build/miniz-sys-5f6a8260c5d6f474/out/miniz.o" "-c" "miniz.c"
cargo:warning=Assembler messages:
cargo:warning=Fatal error: selected target format 'elf64-littleaarch64' unknown
ExitStatus(ExitStatus(256))

The problem is from cargo setting LD_LIBRARY_PATH with /usr/lib (where /usr is the --print=sysroot value). It also adds that path before adding the LD_LIBRARY_PATH from the environment, so it can't be overridden. I thought of specifying --sysroot via RUSTFLAGS to change the LD_LIBRARY_PATH value, but env_args in context.rs forbids this. (See #4423.)

So far, I have only managed to get these builds working by either wrapping rustc in a script that adds --sysroot, or by wrapping the cross-compilers in a script that unsets LD_LIBRARY_PATH. Am I missing a better way to handle this?

@alexcrichton
Copy link
Member

Hm Cargo nowadays shouldn't be setting LD_LIBRARY_PATH to system directories, what version are you using?

@dm0-
Copy link
Author

dm0- commented Sep 1, 2017

I tried 0.20.0 and 0.21.0.

It seems to be creating the system libdir path at https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/cargo_rustc/context.rs#L288 and adding it to LD_LIBRARY_PATH at https://github.com/rust-lang/cargo/blob/master/src/cargo/ops/cargo_rustc/compilation.rs#L128 .

@alexcrichton
Copy link
Member

Oh interesting! You've got rustc installed at /usr?

I didn't even realize we had that block, but yeah we probably shouldn't be setting that in LD_LIBRARY_PATH regardless there (but rather pursuing alternate solutions)

@dm0-
Copy link
Author

dm0- commented Sep 1, 2017

Yes, this is the default setup on Gentoo. If it avoids setting LD_LIBRARY_PATH altogether here, that should solve my problem. Thanks.

@carols10cents carols10cents added A-environment-variables Area: environment variables A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-bug Category: bug labels Oct 3, 2017
@stale
Copy link

stale bot commented Sep 20, 2018

As there hasn't been any activity here in over 6 months I've marked this as stale and if no further activity happens for 7 days I will close it.

I'm a bot so this may be in error! If this issue should remain open, could someone (the author, a team member, or any interested party) please comment to that effect?

The team would be especially grateful if such a comment included details such as:

  • Is this still relevant?
  • If so, what is blocking it?
  • Is it known what could be done to help move this forward?

Thank you for contributing!

(The cargo team is currently evaluating the use of Stale bot, and using #6035 as the tracking issue to gather feedback.)

If you're reading this comment from the distant future, fear not if this was closed automatically. If you believe it's still an issue please leave a comment and a team member can reopen this issue. Opening a new issue is also acceptable!

@stale stale bot added the stale label Sep 20, 2018
@stale
Copy link

stale bot commented Oct 20, 2018

As I didn't see any updates in 30 days I'm going to close this. Please see the previous comment for more information!

@stale stale bot closed this as completed Oct 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-environment-variables Area: environment variables A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants