Use linker from environment variable

I use bitbake / yocto for a custom linux distribution.
Bitbake builds a gcc for my target and an SDK that contains all libraries and that compiler.
Also it provides an environment file which I can source which sets all the paths for me correctly.

One of that environment variables is the $CC variable, which looks like this on my target:

arm-hulu-linux-gnueabi-gcc -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/hulu/4.0/sysroots/cortexa7t2hf-neon-vfpv4-hulu-linux-gnueabi

Yes, that environment variable contains spaces and all needed command line arguments.

How do I tell cargo to use $CC and the linker arguments?

I know that I can set it using .cargo/config by hand, but I want it to use the $CC variable. Is there a chance?

The CC variable is for invoking a C compiler, not for invoking a linker. You can use CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABI_LINKER to set the linker cargo will use for the arm-unknown-linux-gnueabi target. Most other options in .cargo/config.toml and all the profile options in Cargo.toml can be set using similar env vars.

As for adding command line arguments you need to pass them in the -Clink-args rustc argument using RUSTFLAGS.

I was under the impression that cc is used, because if I do not specify a linker at all, the following error occurs:

error: linking with `cc` failed: exit status: 1

that's why I thought it's $CC instead of $LD

For reference, this is what my $LD contains:

arm-hulu-linux-gnueabi-ld --sysroot=/opt/hulu/4.0/sysroots/cortexa7t2hf-neon-vfpv4-hulu-linux-gnueabi

And indeed, I need to use the $CC variable as a linker, because else I get this error:

= note: arm-hulu-linux-gnueabi-ld: cannot find -lgcc: No such file or directory

I just need a more convenient way to specify it :confused:

Can you wrap that command in a bash script that's on your $PATH and use that as the linker?

I guess I could? I guess that's the best way to do it. Thanks for the thought.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.