d9ngle
d9ngle

Reputation: 1469

CMAKE_CXX_COMPILER_VERSION is pointing to the old GCC version

I have upgraded my GCC using:

$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update
$ sudo apt-get install gcc-8 g++-8
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 70 --slave /usr/bin/g++ g++ /usr/bin/g++-8

Running any of these commands:

$ gcc --version
$ g++ --version
$ c++ --version
$ /usr/bin/gcc --version
$ /usr/bin/g++ --version
$ /usr/bin/c++ --version

would show (Ubuntu 8.1.0-5ubuntu1~16.04) 8.1.0 confirming that version 8.1 has been installed.

When running ./configure on cmake-3.12.1 I downloaded from its website I get:

-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0

However when trying to make my actual project:

CMake Error at CMakeLists.txt:24 (message):
  GCC version must be at least 7.1! 5.4.0

This is my CMakeLists.txt:

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    # require at least gcc 7.1
    if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.1)
        message(FATAL_ERROR "GCC version must be at least 7.1!  " ${CMAKE_CXX_COMPILER_VERSION})
    endif()
endif()

Upvotes: 15

Views: 13298

Answers (1)

d9ngle
d9ngle

Reputation: 1469

As Shawn, Tsyvarev and hellow have mentioned in the comments, this problem is caused by CMake cache file which was located inside /build/. Deleting the file solved the issue.

Upvotes: 9

Related Questions