【问题标题】:Why would g++ be unable to find system includes which are installed?为什么 g++ 无法找到已安装的系统包含?
【发布时间】:2016-03-08 23:56:44
【问题描述】:

这是一个在我的桌面 linux 机器(Ubuntu 14.04 64 bit intel,fwiw)上编译的简单示例程序:

#include <iostream>
#include <cmath>

using namespace std;

int main(){
  cout<<"hello"<<endl;
  return 0;
}

当我尝试在似乎安装了头文件(和 build-essential 的等效项)的嵌入式机器上编译它时:

me@t4240rdb:~$ ls /usr/include/c++/4.9.2/iostream
/usr/include/c++/4.9.2/iostream
me@t4240rdb:~# find /usr/include/ -name cmath
/usr/include/c++/4.9.2/ext/cmath
/usr/include/c++/4.9.2/cmath
/usr/include/c++/4.9.2/tr1/cmath

使用g++ /home/me/tc.cpp,我明白了

/home/me/tc.cpp:1:20: fatal error: iostream: No such file or directory
 #include <iostream>
                    ^
compilation terminated.

有人知道为什么会发生这种情况吗?

包括在 cmets 中要求的 g++ -v 的输出:

me@t4240rdb:~# g++ -v /home/me/tc.cpp 
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/gcc/powerpc64-fsl-linux/4.9.2/lto-wrapper
Target: powerpc64-fsl-linux
Configured with: /home/jenkins/ci/iso-make/master/b4860qds-64b/build_b4860qds-64b/tmp/work-shared/gcc-4.9.2-r0/gcc-4.9.2/configure --build=x86_64-linux --host=powerpc64-fsl-linux --target=powerpc64-fsl-linux --prefix=/usr --exec_prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib64/gcc --datadir=/usr/share --sysconfdir=/etc --sharedstatedir=/com --localstatedir=/var --libdir=/usr/lib64 --includedir=/usr/include --oldincludedir=/usr/include --infodir=/usr/share/info --mandir=/usr/share/man --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot=/home/jenkins/ci/iso-make/master/b4860qds-64b/build_b4860qds-64b/tmp/sysroots/b4860qds-64b --with-gnu-ld --enable-shared --enable-languages=c,c++ --enable-threads=posix --enable-multilib --enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=powerpc64-fsl-linux- --without-local-prefix --enable-target-optspace --enable-lto --enable-libssp --disable-bootstrap --disable-libmudflap --with-system-zlib --with-linker-hash-style=gnu --enable-linker-build-id --with-ppl=no --enable-checking=release --enable-cheaders=c_global --with-sysroot=/ --with-build-sysroot=/home/jenkins/ci/iso-make/master/b4860qds-64b/build_b4860qds-64b/tmp/sysroots/b4860qds-64b --with-native-system-header-dir=/home/jenkins/ci/iso-make/master/b4860qds-64b/build_b4860qds-64b/tmp/sysroots/b4860qds-64b/usr/include --with-gxx-include-dir=/usr/include/c++/4.9.2 --with-long-double-128 --enable-nls --enable-__cxa_atexit
Thread model: posix
gcc version 4.9.2 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc'
 /usr/lib64/gcc/gcc/powerpc64-fsl-linux/4.9.2/cc1plus -quiet -v -D_GNU_SOURCE -D__unix__ -D__gnu_linux__ -D__linux__ -Dunix -D__unix -Dlinux -D__linux -Asystem=linux -Asystem=unix -Asystem=posix /home/me/tc.cpp -quiet -dumpbase tc.cpp -auxbase tc -version -o /tmp/cc4avGfH.s
GNU C++ (GCC) version 4.9.2 (powerpc64-fsl-linux)
    compiled by GNU C version 4.9.2, GMP version 6.0.0, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "usr/include/c++/4.9.2"
ignoring nonexistent directory "usr/include/c++/4.9.2/powerpc64-fsl-linux"
ignoring nonexistent directory "usr/include/c++/4.9.2/backward"
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/lib64/gcc/powerpc64-fsl-linux/4.9.2/../../../../powerpc64-fsl-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib64/gcc/powerpc64-fsl-linux/4.9.2/include
 /usr/lib64/gcc/powerpc64-fsl-linux/4.9.2/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.9.2 (powerpc64-fsl-linux)
    compiled by GNU C version 4.9.2, GMP version 6.0.0, MPFR version 3.1.2, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 63db6eac369c397424f29967693724f9
/home/me/tc.cpp:1:20: fatal error: iostream: No such file or directory
 #include <iostream>
                    ^
compilation terminated.

这很有趣——配置显然有问题。我如何解决它?

【问题讨论】:

  • 试试g++ -v /home/me/tc.cpp - 并在你的问题中发布它的输出,因为它通常不可读[并且可能太长]无法发表评论。
  • 我更新了你的标签,因为我 99% 确定它不是特定于 4.9 [我在工作中的 Ubuntu 机器上使用 4.9,我很确定这就是我的家用机器所拥有的也是,但我主要在家里使用clang]
  • 您的输出给出了错误:#include &lt;...&gt; search starts here: ...,而这些路径都不是您的iostream 所在的位置。它进一步指出“usr/include/c++/4.9.2”不存在。您需要将这些路径更新为 /usr/include/c++/4.9.2(确保包含前导斜杠)。
  • 标题应该在 /usr/lib64/gcc/powerpc64-fsl-linux/4.9.2/include 中。如果该路径不存在,那么您需要找出原因。我建议 not 将其链接/复制到 /usr/include (好吧,除非您用尽了其他选项),这些可能是不同编译器或不同版本编译器的标头,从而导致奇怪的问题.
  • 我会 1) 重新安装 g++ (sudo apt-get install gcc) 或 2) 重新运行 g++ (./configure) 的配置脚本或 3) 两者。当涉及到 g++ 配置时,它可能是残酷的,有时最好/最快的解决方法就是将其全部清除。

标签: c++ linux g++


【解决方案1】:

所以这被证明是 gcc 中的一个错误,将其配置为 sysroot 设置为 '/' 会导致这个问题。它是在 gcc 4.7.2 中发现的,但在 gcc 4.9.2 中仍然存在问题。我有一个补丁可以解决这个问题,并且已经开始尝试了解如何让 bitbake 使用该补丁重建目标 gcc,所以我将回答这个问题。

这里是关于错误和补丁的电子邮件:https://gcc.gnu.org/ml/gcc-patches/2012-02/msg00320.html

【讨论】:

    猜你喜欢
    • 2016-01-28
    • 2016-06-30
    • 2012-12-14
    • 2021-03-04
    • 2021-06-20
    • 1970-01-01
    • 2017-09-17
    • 2020-07-03
    • 1970-01-01
    相关资源
    最近更新 更多