Adding linker to the PATH

For compiling for Android, we need to generate linker, ad call it in the .cargo/config, I got the required linkers, saved them in the project root, and called them in the /.cargo/config as:

[target.x86_64-linux-android]
ar = "<project_root>/ndk_for_rust/x86_64/bin/x86_64-linux-android-ar"
linker = "<project_root>/ndk_for_rust/x86_64/bin/x86_64-linux-android-clang"

And everything moved smoothly.

Now i need to create another project, so to avoid having multiple copies of my ndk_for_rust folder, I added to the path $HOME/.bash_profile as:

export NDK_FOR_RUST_HOME=/usr/local/ndk_for_rust

And tried to call it in the .cargo/config as:

[target.x86_64-linux-android]
ar = "${NDK_FOR_RUST_HOME}/ndk_for_rust/x86_64/bin/x86_64-linux-android-ar"
linker = "${NDK_FOR_RUST_HOME}/ndk_for_rust/x86_64/bin/x86_64-linux-android-clang"

But got the below error upon running cargo build --target x86_64-linux-android --release:

error: linker `/Users/h_ajsf/IdeaProjects/rust_app02/${NDK_FOR_RUST_HOME}/x86_64/bin/x86_64-linux-android-clang` not found                                                                  
  |                                                                                                                                                                                            
  = note: No such file or directory (os error 2)

Is there a way to use a linker to a location outside my project root, so I avoid having multiple copies?

What I did was add the linker etc, to my path directly, so that the config file doesn’t have to worry about environment variables

How did you call the linker from you config file? or do you mean you did not use config file?

Sorry for the late reply, when I originally replied, I wasn’t at my pc. When I use WSL to run my android app, I use the following .cargo/conf and I actually have the linker and stuff in a separate place:

[target.x86_64-pc-windows-gnu]
linker = "/usr/bin/x86_64-w64-mingw32-gcc"

[target.i686-pc-windows-gnu]
linker = "/usr/bin/i686-w64-mingw32-gcc"
rustflags = "-C panic=abort"