c++ - g++ 找不到标准 header (iostream、字符串等)

标签 c++ c++11

我的测试代码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) 

我该如何解决这个问题?感谢您的帮助。


ok,这就是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.

最佳答案

这很可能是因为没有安装 libstdc++-devel 包。

您的编译器版本表明您正在运行 RHEL、CentOS 或 Fedora。执行以下命令:

yum install libstdc++-devel

关于c++ - g++ 找不到标准 header (iostream、字符串等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28422781/

相关文章:

c++ - 这段代码如何从元组中提取参数?

c++ - 在嵌套模板结构中将引用类型作为模板参数传递不起作用

C++ 结构未通过 POD 测试

c++ - `std::kill_dependency` 有什么作用,我为什么要使用它?

javascript - C++11 标准引用 ECMAScript (Javascript) 规范?

c++ - SendMessage 到 64 位应用程序不起作用

c++ - 为什么在删除适配器的默认 IP 时 DeleteIPAddress 会失败?

python - Tensorflow C++ 评估性能比 Python 差

C++ - 如何将静态数组放入我的数组中?

c++ - 方法超出范围后是否应该删除引用的 std::shared_ptr ?