我的测试代码test.cpp
:
#include <iostream>
using namespace std;
int main(){
cout<<"hello"<<endl;
return 0;
}
当我通过g++ test.cpp
编译时,我收到以下错误:
fatal error: iostream: No such file or directory
我的环境:
#g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/lto-wrapper
Target: armv7hl-redhat-linux-gnueabi
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --disable-build-with-cxx --disable-build-poststage1-with-cxx --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,go,lto --enable-plugin --enable-initfini-array --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --disable-sjlj-exceptions --with-cpu=cortex-a8 --with-tune=cortex-a8 --with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16 --with-abi=aapcs-linux --build=armv7hl-redhat-linux-gnueabi
Thread model: posix
gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC)
如何解决此问题?感谢您的帮助。
好的,这是g++ -v test.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/lto-wrapper
Target: armv7hl-redhat-linux-gnueabi
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --disable-build-with-cxx --disable-build-poststage1-with-cxx --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,go,lto --enable-plugin --enable-initfini-array --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --disable-sjlj-exceptions --with-cpu=cortex-a8 --with-tune=cortex-a8 --with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16 --with-abi=aapcs-linux --build=armv7hl-redhat-linux-gnueabi
Thread model: posix
gcc version 4.7.2 20121109 (Red Hat 4.7.2-8) (GCC)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-march=armv7-a' '-mtune=cortex-a8' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mabi=aapcs-linux' '-mtls-dialect=gnu'
/usr/libexec/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/cc1plus -quiet -v -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -march=armv7-a -mtune=cortex-a8 -mfloat-abi=hard -mfpu=vfpv3-d16 -mabi=aapcs-linux -mtls-dialect=gnu -auxbase test -version -o /tmp/cctwdZCf.s
GNU C++ (GCC) version 4.7.2 20121109 (Red Hat 4.7.2-8) (armv7hl-redhat-linux-gnueabi)
compiled by GNU C version 4.7.2 20121109 (Red Hat 4.7.2-8), GMP version 5.0.5, MPFR version 3.1.1, MPC version 0.9
GGC heuristics: --param ggc-min-expand=85 --param ggc-min-heapsize=104357
ignoring nonexistent directory "/usr/lib/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/../../../../include/c++/4.7.2"
ignoring nonexistent directory "/usr/lib/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/../../../../include/c++/4.7.2/armv7hl-redhat-linux-gnueabi"
ignoring nonexistent directory "/usr/lib/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/../../../../include/c++/4.7.2/backward"
ignoring nonexistent directory "/usr/lib/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/../../../../armv7hl-redhat-linux-gnueabi/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/armv7hl-redhat-linux-gnueabi/4.7.2/include
/usr/local/include
/usr/include
End of search list.
GNU C++ (GCC) version 4.7.2 20121109 (Red Hat 4.7.2-8) (armv7hl-redhat-linux-gnueabi)
compiled by GNU C version 4.7.2 20121109 (Red Hat 4.7.2-8), GMP version 5.0.5, MPFR version 3.1.1, MPC version 0.9
GGC heuristics: --param ggc-min-expand=85 --param ggc-min-heapsize=104357
Compiler executable checksum: cab4eacd06fac4cf3a5e1bf6dac7fc2e
test.cpp:1:20: fatal error: iostream: No such file or directory
compilation terminated.
答案 0 :(得分:3)
这很可能是由于没有安装libstdc ++ - devel软件包。
您的编译器版本表明您正在运行RHEL,CentOS或Fedora。执行以下命令:
yum install libstdc++-devel