c++ - gcc-4.8无法编译测试程序?

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

我在 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 一起工作,那么我可能会缺少什么?

最佳答案

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

关于c++ - gcc-4.8无法编译测试程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46858807/

相关文章:

linux - 我如何通过 socialvpn 运行 diaspora pod?

c++ - 文档{}的mongodb C++驱动程序编译错误

c++ - 模板成员函数调用—— "error: expected primary-expression before ' int'”

c++ - cmake Eigen find_package提示

c++ - 可选未初始化的类: std::is_trivially_constructible 对于非默认构造函数似乎不正确?

linux - 由于互联网连接丢失而导致 SSH session 终止也会导致正在运行的进程终止

python - 未找到 Ansible Firewalld 模块

c++ - std::unique_ptr 的推荐用法

Java ArrayList 与 C++ std::vector

c++ - 使用异步 I/O 和 IOCP 实现回声服务器的最佳方法是什么?