-2

I've installed gcc-4.8 on Ubuntu 16.04 to build a C++11 program. I have a CMakeList.txt file that worked well on OS X with Clang and GCC 4.8 built from Macports.

I started by setting CXX=/usr/bin/gcc-4.8 and then CMake fails with the following error:

-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/gcc-4.8
-- Check for working CXX compiler: /usr/bin/gcc-4.8 -- broken
CMake Error at /usr/share/cmake-3.5/Modules/CMakeTestCXXCompiler.cmake:54 (message):
  The C++ compiler "/usr/bin/gcc-4.8" is not able to compile a simple test
  program.

  It fails with the following output:

   Change Dir: /home/ruipacheco/databaseclient/cpp/ninja/CMakeFiles/CMakeTmp          

  Run Build Command:"/usr/bin/make" "cmTC_5df0c/fast"

  /usr/bin/make -f CMakeFiles/cmTC_5df0c.dir/build.make
  CMakeFiles/cmTC_5df0c.dir/build

  make[1]: Entering directory
  '/home/ruipacheco/databaseclient/cpp/ninja/CMakeFiles/CMakeTmp'

  Building CXX object CMakeFiles/cmTC_5df0c.dir/testCXXCompiler.cxx.o

  /usr/bin/gcc-4.8 -o CMakeFiles/cmTC_5df0c.dir/testCXXCompiler.cxx.o -c
  /home/ruipacheco/databaseclient/cpp/ninja/CMakeFiles/CMakeTmp/testCXXCompiler.cxx

  gcc-4.8: error trying to exec 'cc1plus': execvp: No such file or directory

  CMakeFiles/cmTC_5df0c.dir/build.make:65: recipe for target
  'CMakeFiles/cmTC_5df0c.dir/testCXXCompiler.cxx.o' failed

  make[1]: *** [CMakeFiles/cmTC_5df0c.dir/testCXXCompiler.cxx.o] Error 1

  make[1]: Leaving directory
  '/home/ruipacheco/databaseclient/cpp/ninja/CMakeFiles/CMakeTmp'

  Makefile:126: recipe for target 'cmTC_5df0c/fast' failed

  make: *** [cmTC_5df0c/fast] Error 2

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:6 (project)

-- Configuring incomplete, errors occurred!

Again, I know gcc-4.8 is capable of building C++11 programs and I've managed to make this CMakeLists.txt file work with gcc 4.8 on OSX so what could I be missing?

jww
  • 97,681
  • 90
  • 411
  • 885
ruipacheco
  • 15,025
  • 19
  • 82
  • 138
  • Maybe regex support? – Kerrek SB Oct 21 '17 at 00:06
  • C++11 support before version 5 was still incomplete. What is the reason you decided for such an old version (it's up to over 7 now)? – Some programmer dude Oct 21 '17 at 00:08
  • Please [edit] your question to provide a [mcve]. – Baum mit Augen Oct 21 '17 at 00:09
  • 4
    You only installed gcc's C compiler. You did not install the C++ compiler. This is painfully obvious from the shown error message. – Sam Varshavchik Oct 21 '17 at 00:16
  • I believe you are also supposed to `set project(, CXX)` to inform CMake you are using C++ tools, but that does not work with CMake. Also see [Tell CMake to use C++ compiler for C files coming from CMake?](https://stackoverflow.com/q/37931068/608639) – jww Oct 21 '17 at 00:42
  • @Someprogrammerdude - GCC 4.8 still shows up in a lot of places, from ARM dev-boards to hosts on GCC's compile farm, like [GCC 112 and GCC119](https://gcc.gnu.org/wiki/CompileFarm). Its amazing how popular GCC 4.8 and even 4.9 are (still?). – jww Oct 21 '17 at 00:49

1 Answers1

4

"gcc-4.8" is a C compiler, not a C++ compiler. You should set the CXX variable to "g++-4.8" or "g++" or some other C++ compiler executable.

aschepler
  • 70,891
  • 9
  • 107
  • 161
  • Out of a morbid curiosity, would `-x c++` also work? Maybe something like `CXX="gcc-4.8 -x c++"`. – jww Oct 21 '17 at 00:46
  • 2
    @jww If g++-4.8 is not installed, not a chance. If g++-4.8 is installed to the same place as gcc-4.8, it will successfully compile, but won't automatically add the standard C++ library when used in a link step. – aschepler Oct 21 '17 at 00:52