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

Support setting "-C linker=" for rustc #1109

Closed
hukka opened this issue Dec 31, 2014 · 16 comments
Closed

Support setting "-C linker=" for rustc #1109

hukka opened this issue Dec 31, 2014 · 16 comments

Comments

@hukka
Copy link

hukka commented Dec 31, 2014

Some cross compilation tools have prefixes in their name and path, for example the armel linker on Debian is /usr/bin/arm-linux-gnueabi-gcc. Cross compile targets would need a way to specify -C linker for rustc in the manifest.

@alexcrichton
Copy link
Member

This is currently possible today via target.$triple.linker, and more flags are covered by #544.

@hukka
Copy link
Author

hukka commented Dec 31, 2014

Mea culpa. Missed that whole page and just read the guide and the manifest docs.

@mpe
Copy link

mpe commented Jan 14, 2015

For anyone else who doesn't read the documentation properly, the target.$triple.linker settings goes in .cargo/config not in Cargo.toml. If you put it in Cargo.toml it will be silently ignored.

eg:

[target.arm-unknown-linux-gnueabi]
linker = "/usr/bin/arm-linux-gnueabi-gcc"

@tigerleapgorge
Copy link

If you put it in Cargo.toml it will be silently ignored.

Isn't that rather error prone?

@rightfold
Copy link

How do I find my target triple?

@alexcrichton
Copy link
Member

@rightfold if you run rustc -vV it'll tell you the default target that you compile for (under host), otherwise you're passing --target in which case that's the target triple.

@rightfold
Copy link

rightfold commented Feb 12, 2017 via email

@jeroen
Copy link

jeroen commented May 4, 2018

Is there any way to set the linker via an environment variable or cargo parameter rather than a config file?

jeroen added a commit to r-rust/gifski that referenced this issue May 4, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
jeroen added a commit to r-rust/gifski that referenced this issue May 5, 2018
@alexcrichton
Copy link
Member

@jeroen you should be able to set configuration via env vars

@jeroen
Copy link

jeroen commented May 5, 2018

@alexcrichton what environment variable would I use to set the linker for target.x86_64-pc-windows-gnu and target.i686-pc-windows-gnu?

@jeroen
Copy link

jeroen commented May 5, 2018

Or just in general can I set the linker for the current cargo build (any target) with an environment variable? I tried:

  • LD
  • LINKER
  • CARGO_BUILD_LINKER
  • CARGO_TARGET_i686-pc-windows-gnu_LINKER

But none had the same effect as a config file containing:

[target.i686-pc-windows-gnu]
linker = "c:/Rtools/mingw_32/bin/gcc"

@alexcrichton
Copy link
Member

@jeroen you'd use CARGO_TARGET_I686_PC_WINDOWS_GNU_LINKER

@jeroen
Copy link

jeroen commented May 7, 2018

Thanks @alexcrichton! Now I am stuck on one final issue:

We use a version of mingw-builds that was compiled with --static-gcc. Therefore our toolchain does not contain a copy of libgcc_eh.a, instead those objects are available from libgcc.a.

Currently when I try to build imageoptim-sys the linker fails because it can't find libgcc_eh.a. I think that is because this flag is hardcoded in rust. Is there some way I can tell rust that my linker wants to be linked with -lgcc instead of -lgcc_eh?

The cmake folks have a similar topic about not linking to libgcc_eh directly.

@alexcrichton
Copy link
Member

@jeroen ah unforutnately you can't change that right now, so the only recourse would be to write a wrapper script that translates -lgcc_eh to -lgcc, it's not great :(

@lobianco
Copy link

For anyone who stumbles into this thread looking for an answer that doesn't involve .cargo/config, you can set the linker as a parameter of your cargo command like this:

RUSTFLAGS="-C linker=/path/to/linker" cargo run ...

@sanmai-NL
Copy link

@jeroen ah unforutnately you can't change that right now, so the only recourse would be to write a wrapper script that translates -lgcc_eh to -lgcc, it's not great :(

See rust-lang/rust#29527

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

No branches or pull requests

8 participants