0
下面是一個簡單的例子程序,編譯我的桌面Linux機器(Ubuntu的14.04 64位Intel,FWIW):爲什麼g ++無法找到安裝的系統包含?
#include <iostream>
#include <cmath>
using namespace std;
int main(){
cout<<"hello"<<endl;
return 0;
}
當我嘗試編譯它出現有頭文件的嵌入式機器上(和安裝建立必要的)相當於:使用g++ /home/me/tc.cpp
[email protected]:~$ ls /usr/include/c++/4.9.2/iostream
/usr/include/c++/4.9.2/iostream
[email protected]:~# 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
,我得到
/home/me/tc.cpp:1:20: fatal error: iostream: No such file or directory
#include <iostream>
^
compilation terminated.
任何人都有一個呃想知道爲什麼會發生這種情況?
包括輸出的要求,在評論G ++ -v:
[email protected]:~# 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 /家/我/ tc.cpp' - 和後期從輸出你的問題,因爲它通常是不可讀[和可能太長了]的評論。 –
我更新代碼,因爲我99%肯定它不是具體到4.9 [我我的Ubuntu的機器上使用4.9的工作,我相當肯定這是我家的機器有什麼過,但我一直都用鐺在家] –
你的輸出給你錯誤:'#include <...>搜索從這裏開始:...'並且這些路徑都不是你的'iostream'所在的地方。它進一步指出「usr/include/C++/4.9.2'」不存在。您需要將這些路徑更新爲'/ usr/include/C++/4.9.2'(確保包含前導斜槓)。 – callyalater