我是linux的初学者,当我在我的raspberry pi上运行我的第一个程序"HELLOWORLD“时,出现了这个警告:
pi@raspberrypi:~/raspitest $ g++ test.cpp -o test
In file included from /usr/include/c++/8/ext/string_conversions.h:41,
from /usr/include/c++/8/bits/basic_string.h:6400,
from /usr/include/c++/8/string:52,
from /usr/include/c++/8/bits/locale_classes.h:40,
from /usr/include/c++/8/bits/ios_base.h:41,
from /usr/include/c++/8/ios:42,
from /usr/include/c++/8/ostream:38,
from /usr/include/c++/8/iostream:39,
from test.cpp:1:
/usr/include/c++/8/cstdlib:75:15: fatal error: stdlib.h: No No such file or directory
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
我没有使用任何make工具,只是通过vim编写代码并运行以下命令:pi@raspberrypi:~/raspitest $ g++ test.cpp -o test
stdlib.h应该位于正确的路径中:
pi@raspberrypi:~/raspitest $ locate stdlib.h
/opt/Wolfram/WolframEngine/12.1/SystemFiles/Links/ArduinoLink/Resources/CSource/avr-libc/1.8.1/avr/include/stdlib.h
/usr/include/stdlib.h
/usr/include/arm-linux-gnueabihf/bits/stdlib.h
/usr/include/c++/8/stdlib.h
/usr/include/c++/8/tr1/stdlib.h
/usr/include/freetype2/freetype/config/ftstdlib.h
以下是我的原始代码:
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
cout <<"hello,world" << endl;
return 0;
}
下面是g++ -v test.cpp
的输出
pi@raspberrypi:~/raspitest $ g++ -v test.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/8/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Raspbian 8.3.0-6+rpi1' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --disable-werror --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 8.3.0 (Raspbian 8.3.0-6+rpi1)
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mfloat-abi=hard' '-mfpu=vfp' '-mtls-dialect=gnu' '-marm' '-march=armv6+fp'
/usr/lib/gcc/arm-linux-gnueabihf/8/cc1plus -quiet -v -imultilib . -imultiarch arm-linux-gnueabihf -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mfloat-abi=hard -mfpu=vfp -mtls-dialect=gnu -marm -march=armv6+fp -auxbase test -version -o /tmp/cchrh8l9.s
GNU C++14 (Raspbian 8.3.0-6+rpi1) version 8.3.0 (arm-linux-gnueabihf)
compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.20-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/arm-linux-gnueabihf/c++/8"
ignoring nonexistent directory "/usr/local/include/arm-linux-gnueabihf"
ignoring nonexistent directory "/usr/lib/gcc/arm-linux-gnueabihf/8/../../../../arm-linux-gnueabihf/include"
ignoring duplicate directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include
/usr/include/c++/8
/usr/include/arm-linux-gnueabihf/c++/8
/usr/include/c++/8/backward
/usr/lib/gcc/arm-linux-gnueabihf/8/include
/usr/local/include
/usr/lib/gcc/arm-linux-gnueabihf/8/include-fixed
/usr/include/arm-linux-gnueabihf
End of search list.
GNU C++14 (Raspbian 8.3.0-6+rpi1) version 8.3.0 (arm-linux-gnueabihf)
compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.20-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 7defdc925cf5fede452fc531d54623d1
In file included from /usr/include/c++/8/ext/string_conversions.h:41,
from /usr/include/c++/8/bits/basic_string.h:6400,
from /usr/include/c++/8/string:52,
from /usr/include/c++/8/bits/locale_classes.h:40,
from /usr/include/c++/8/bits/ios_base.h:41,
from /usr/include/c++/8/ios:42,
from /usr/include/c++/8/ostream:38,
from /usr/include/c++/8/iostream:39,
from test.cpp:1:
/usr/include/c++/8/cstdlib:75:15: fatal error: stdlib.h: 没有那个文件或目录
#include_next <stdlib.h>
^~~~~~~~~~
compilation terminated.
发布于 2021-02-22 18:52:48
感谢评论中的提示。这是我的解决方案:添加
CPLUS_INCLUDE_PATH=$CPLUSE_INCLUDE_PATH:/usr/include/c++/8
export CPLUS_INCLUDE_PATH
转换为~/.bashrc
文件。如果仍然不起作用,请尝试重新启动或将所有头文件复制到新文件夹中,然后再次更改cplus_path。
https://stackoverflow.com/questions/66304331
复制相似问题