【问题标题】:why self built g++ compiler fails to compile my code为什么自建 g++ 编译器无法编译我的代码
【发布时间】:2014-10-03 12:59:06
【问题描述】:

我想在 suse linux 上使用最新的 g++ 编译器(4.9.1),但 suse 只支持旧的 g++ 版本。因此,我从其中一个 gnu 镜像站点获取了最新的源代码并自己编译了它。一切都很顺利。但是当我尝试使用内置的 g++ 编译我的测试代码时,编译失败并出现错误, “/root/home/include/c++/4.9.1/x86_64-unknown-linux-gnu/bits/os_defines.h:39:22:致命错误:features.h:没有这样的文件或目录”。

我可以在“/root/home/include/c++/4.9.1/parallel”中找到一个“features.h”,但我觉得应该存在于“/root/home/include/c++/4.9.1/”本身中。

我将“/root/home/include/c++/4.9.1/parallel/features.h”复制到“/root/home/include/c++/4.9.1/ ”只是为了看看会发生什么。现在它抱怨找不到错误“whcar.h”。

我错过了什么吗?

这是我构建 g++ 所遵循的步骤。

1. /root/home/gcc_build/objdir# ../gcc-4.9.1/configure --prefix=/root/home/ --disable-multilib
2. /root/home/gcc_build/objdir# make -j16
3. /root/home/gcc_build/objdir# make install
4. /root/home/gcc_build/test#  /root/home/bin/g++ --sysroot /root/home -m64 test.cpp

【问题讨论】:

  • 您是执行安装以添加前缀还是仅复制可执行文件?
  • @Tanuki 我不知道 OP 做了什么,但是安装到前缀 not 解决了这个问题。

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


【解决方案1】:

我通过删除 sysroot 选项并将 c++ 包含和库路径指向我的主目录解决了这个问题。我注意到的一件事是 g++ 源不附带 libc 和 c 头文件,并且 libc 必须单独安装。但是使用 sysroot 选项,g++ 试图查看我的主目录中的所有头文件。

下面是我用来成功编译代码的命令。

/root/home/bin/g++ -I /root/home/include/c++/4.9.1 -L /root/home/lib64 -Wl,--rpath=/root/home/lib64 --std=c++0x -m64 test.cpp

【讨论】:

    【解决方案2】:

    看看GCC Directory Options。使用正确的“说明符”也很重要(-isystem、-L、-B、-I 等)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      • 1970-01-01
      • 1970-01-01
      • 2017-07-09
      • 1970-01-01
      • 1970-01-01
      • 2016-01-08
      相关资源
      最近更新 更多