/usr/include/c++/8/cstdlib:75:15: fatal error: stdlib.h: No such file or directory

I'm a beginner in linux and when I was running my first program "HELLOWORLD" on my raspberry pi this warning appeared: I was not using any make tools, just wrote the code via vim and ran the following command: pi@raspberrypi:~/raspitest $ g++ test.cpp -o test

I'm a beginner in linux and when I was running my first program "HELLOWORLD" on my raspberry pi this warning appeared:

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. 

I was not using any make tools, just wrote the code via vim and ran the following command: pi@raspberrypi:~/raspitest $ g++ test.cpp -o test

The stdlib.h should have been in the right path:

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 

here are my original code:

#include<iostream> #include<stdlib.h> using namespace std; int main() { cout <<"hello,world" << endl; return 0; } 

and here is the output of 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. 
7

2 Answers

Thanks for the hints from the comments. Here is my soloution: add

export CPLUS_INCLUDE_PATH=/usr/include/c++/8:$CPLUS_INCLUDE_PATH 

to ~/.bashrcfile. If still not working, try to reboot or copy all the headfiles to a new folder and change the cplus_path again.

I met the same question, and the reason is that I set export C_INCLUDE_PATH="/usr/include/" in my ~/.zshrc file.

When I use g++ -v a.cpp as above, /usr/include is in the top of lines, so comment this env variable, error is disappeared..

ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobW9rYGmAdH2OrqqrZZmjsK3Bw55knGVoYrC0wMOloJtvZWaCbrLArZilZZWnv7C%2BjKyrnaSZl3qpec2oZKytk516p7XLnmSoql2ZtrOxwq2m

 Share!