Reputation: 5191
My problem is simple : if I check the gcc version, I obtain 4.5.1
, but CMake find gcc 4.5.0
:
> /usr/bin/gcc --version
gcc (SUSE Linux) 4.5.1 20101208 [gcc-4_5-branch revision 167585]
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> mkdir BUILD & cd BUILD
> cmake ..
-- The C compiler identification is GNU 4.5.0
-- The CXX compiler identification is GNU 4.5.0
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- The Fortran compiler identification is GNU
-- Check for working Fortran compiler: /usr/bin/gfortran
-- Check for working Fortran compiler: /usr/bin/gfortran -- works
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Checking whether /usr/bin/gfortran supports Fortran 90
-- Checking whether /usr/bin/gfortran supports Fortran 90 -- yes
Who is wrong ? CMake or Gcc ?
I use cmake 2.8.9, but I also have the bug with cmake 3.1.0.
I don't have the bug with gcc 4.7.2, 4.4.7 and 4.1.2.
Upvotes: 5
Views: 13315
Reputation: 43612
The solution I found was similar to @usr1234567 that essentially CMake uses cc
and c++
wherever they are off the $PATH
, which is not always the same as gcc
or g++
.
Specifying these compilers fixes the version shown by CMake:
cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ..
Upvotes: 12
Reputation: 5191
Answering my own question.
Actually, gcc 4.5.1 seems have a bug because the following simple code (correct according to the official doc : https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html) prints 4.5.0
when compiled with gcc 4.5.1 on my workstation.
#include <iostream>
int main(int argc, char** argv)
{
std::cout << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__ << std::endl;
return 0;
}
Upvotes: 1
Reputation: 23294
CMake uses /usr/bin/c++
probably this is still pointing to gcc 4.5.0. If you want to set the compiler, add -DCMAKE_CXX_COMPILER
to the compiler you like.
Upvotes: 1