There is the same question and the answer.
The problem is that the answer seems to be wrong (actually is not the answer to the asked question). Can I re-ask the question?
The problem:
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ whereis gcc
cc: /usr/bin/gcc /usr/lib/gcc /usr/local/bin/gcc /usr/libexec/gcc
$ which gcc
/usr/local/bin/gcc
$ /usr/bin/gcc -v
gcc version 4.1.2
$ /usr/local/bin/gcc -v
gcc version 4.8.4
$ gcc -v
gcc version 4.8.4
$ cmake .
-- The C compiler identification is GNU 4.1.2
...
...
The local GCC version if 4.8.4 and the system's default version is '4.1.2'. All other tool-chains respects the PATH environment variable and use the local (newer) GCC version. All except of CMAKE.
Setting CC is not a good idea, because there might be other binary tools which could also be used.
Setting CMAKE_PROGRAM_PATH and CMAKE_PREFIX_PATH in the beginning of the script doesn't help with detection of the compilers.
Is there any way to force CMAKE to respect the PATH variable?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…