2

I have a build in an isolated environment that does not have a C++ compiler in PATH. How can I dynamically specify the C++ compiler for cargo to use (for ex: by environment variable)?

It seems as though this is possible, but none of the solutions I've seen appear to match the environment variable docs or in the Cargo.toml [target] docs.

twinlakes
  • 9,438
  • 6
  • 31
  • 42
  • [`target..linker`](https://doc.rust-lang.org/cargo/reference/config.html#targettriplelinker), maybe? – trent Mar 05 '21 at 20:11
  • Do you want to build rust itself? If not, what C++ packages are you trying to build? – HHK Mar 05 '21 at 20:51
  • @trentcl, isn't that only for the linker not the compiler? – twinlakes Mar 05 '21 at 22:44
  • @HHK, both windows toolchains/targets for rust require a C++ compiler under the hood. – twinlakes Mar 05 '21 at 22:44
  • As far as I know, you don't need a C++ compiler to build Rust programs on Windows. The only reason you need Visual C++ Build Tools (on msvc) is for the linker. But I don't personally run on Windows, so I really don't know. – trent Mar 05 '21 at 23:11
  • @trentcl when I target gnu, it requires g++.exe instead of MSVC tools (ex: link.exe). Is g++.exe just used for linking as well? – twinlakes Mar 05 '21 at 23:16
  • 1
    Oh, I think I see what you're confused about -- in some (most?) cases the "linker" actually *is* a compiler, which is not used to compile but just as a frontend to supply the correct system-specific arguments to the actual linker (as also mentioned in [this question](https://stackoverflow.com/q/57812916/3650362)). If you tell it to use a "mere" linker you might need to provide those arguments yourself -- at least, that's how it works on Linux. – trent Mar 06 '21 at 00:11

0 Answers0