【问题标题】:gcc-4.8 can't compile test program? [duplicate]gcc-4.8 不能编译测试程序? [复制]
【发布时间】: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?

标签: c++ linux c++11 gcc cmake


【解决方案1】:

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

【讨论】:

  • 出于病态的好奇,-x c++ 也可以吗?也许像CXX="gcc-4.8 -x c++"
  • @jww 如果没有安装g++-4.8,就没有机会了。如果g++-4.8和gcc-4.8安装在同一个地方,会编译成功,但在链接步骤中使用时不会自动添加标准C++库。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-16
  • 2023-03-31
  • 2012-02-04
  • 2013-03-19
  • 1970-01-01
相关资源
最近更新 更多