1

I want to be able to quickly switch between two compilers, 32bit and 64bit ones. I wonder if just adding correct bin directory to PATH is enough, or I must use CC and CXX?

Here is a somewhat related question, it's about how I add and remove compilers to PATH.

  • The answer is Yes. Did you encounter any problems with this approach? – Florian Sep 13 '17 at 10:15
  • @Florian sorta. It started building for VS2017, which keeps crashing anyway for me. Surprised it found it, it's not even in path. It's a different story though, thanks. – Gregory Balko Sep 13 '17 at 10:46

1 Answers1

0

Turning my comment into an answer

The short answer is, yes CMake will find the compiler in your PATH environment.

The long answer is

  1. It looks what generator/build environment you have specified (e.g. Visual Studio generator searches also in Windows registry for installation paths)
  2. It would check if you specifically specified e.g. CMAKE_CXX_COMPILER CMake variable or if CXX environment variable
  3. It tries to call compilers in the following order (with assumption that one of those is in the PATH environment):

    CC [TOOLCHAIN_PREFIX]c++ [TOOLCHAIN_PREFIX]g++ aCC cl bcc xlC clang++
    

References

Florian
  • 39,996
  • 9
  • 133
  • 149
  • I deleted VS2017, it now gives me an error simular to this one: https://stackoverflow.com/questions/35869564/cmake-on-windows . The difference though, my console can find gcc, but cmake doesn't see it? Could this be due to me setting PATH in console before calling the rest, and cmake only sees system-wide changes? – Gregory Balko Sep 13 '17 at 11:22
  • Yes, and I keep deleting CMakeCache.txt and CMakeFiles, but no difference. – Gregory Balko Sep 13 '17 at 11:24
  • (i'm not sure if you are receiving notifications, so just in case) – Gregory Balko Sep 13 '17 at 11:34
  • @GregoryBalko If you are on Windows, the default is the Visual Studio/NMake generator. Without knowing which GCC you are targeting, I just assume adding `-G "Unix Makefiles"` would solve your problem. – Florian Sep 13 '17 at 11:39