2017-10-21 251 views
-3

我已经在Ubuntu 16.04上安装了gcc-4.8来构建一个C++ 11程序。我有一个CMakeList.txt文件,在Mac OS X操作系统上使用Clang和GCC 4.8可以很好地工作。gcc-4.8无法编译测试程序?

我开始通过设置CXX=/usr/bin/gcc-4.8然后CMake的失败,出现以下错误:

-- 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! 

同样,我知道gcc-4.8有能力建造C++ 11个的程序,我已经成功地使这个CMakeLists.txt档案工作在OSX上使用gcc 4.8,那么我可能会错过什么?

+0

也许正则表达式的支持? –

+0

版本5之前的C++ 11支持仍然不完整。你为什么决定选择这样一个旧版本(现在已经超过7个)? –

+0

请[编辑]你的问题提供[mcve]。 –

回答

3

“gcc-4.8”是一个C编译器,而不是C++编译器。您应该将CXX变量设置为“g ++ - 4.8”或“g ++”或其他C++编译器可执行文件。

+0

出于病态的好奇心,'-x C++'也可以工作吗?也许像'CXX =“gcc-4.8 -x C++”'。 – jww

+2

@jww如果没有安装g ++ - 4.8,不是一个机会。如果将g ++-4.8安装到gcc-4.8的相同位置,它将成功编译,但在链接步骤中使用时不会自动添加标准C++库。 – aschepler