【发布时间】:2023-03-28 11:12:01
【问题描述】:
我在 Ubuntu 16.04 上安装了 gcc-4.8 来构建 C++11 程序。我有一个CMakeList.txt 文件,它在 OS X 上运行良好,使用 Macports 构建的 Clang 和 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 一起工作,所以我还能缺少什么?
【问题讨论】:
-
也许支持正则表达式?
-
第 5 版之前的 C++11 支持仍然不完整。你决定做这么旧的版本的原因是什么(现在已经超过7个了)?
-
请edit您的问题提供minimal reproducible example。
-
你只安装了 gcc 的 C 编译器。您没有安装 C++ 编译器。从显示的错误消息中可以明显看出这一点。
-
我相信您也应该
set project(<name>, CXX)通知 CMake 您正在使用 C++ 工具,但这不适用于 CMake。另见Tell CMake to use C++ compiler for C files coming from CMake?