gcc/4.7.2: fatal error: cstdlib: No such file or directory

I am working with a code that has mostly been developed in C++. There are a few C files too. I'm quite new to programming; this is an engineering code.

I have been using it successfully for months on a Mac, compiled with g++. Now I need to compile it using gcc/4.7.2 and Linux. I am getting this error:

factor.c:35:19: fatal error: cstdlib: No such file or directory

The file, "factor" is one of the few C files I mentioned. It does contain:

#include <cstdlib>

I tried changing it to the "C" version. That didn't work. My understanding is that "cstdlib" should be included by default with the compiler, but I can't find it. Does anyone know how to do a thorough search?

I don't have root privileges on this machine, so I probably can't install it.

I'm stuck and if anyone has any advice, I would be very grateful.
closed account (Dy7SLyTq)
it would be in /usr/include/. i could understand it.... cant believe i didnt see this before...
factor.c:35:19: fatal error: cstdlib: No such file or directory

you cant have a c->c++ (ie x.h -> cx) in a .c file
Thanks very much, DTSCode.

When you say that I can't have c->c++ (ie x.h -> cx) in a .c file, what do you mean? For example, in the C file, should I have:

#include <cstdlib>
(the C++ version)

Or should I have the C version?
closed account (Dy7SLyTq)
the c version. so if you are writing code in a .c file you cant have a cx file. x is a place holder for any one the c headers. so for example:
(c++ can use either c can only use the first column)

c header c++ equivalent
----------- -------------------
stdio.h cstdio
ctypes.h cctypes
string.h cstring
stdlib.h cstdlib
math.h cmath
time.h ctime
Thanks a lot. So I should be using:

#include <stdlib>

It is weird that it isn't working. I did check usr/include and it doesn't look like anything is there. This is a cluster, so maybe the setup is different.

Do you know if it is possible to get it from anywhere else and simply install it in my own directory?
closed account (Dy7SLyTq)
stdlib.h not stdlib. c requires the use of .h headers while c++ uses .h, .hpp, or precompiled (ie the suffix is ommitted)
Thanks very much. I'll give that a try. It takes about 40 minutes to compile.
Hey if you're still there, DTSCode, it did work!! I needed to add an include path to my makefile to

That way, I was able to access "stdlib.h".

Your advice about needing to say <cFile.h> and not <cFile> has been a huge help. Thank you so much. I don't know if I can give you some kind of credit (like marking this answer right) for your help; if I can, I'd be happy to. Just let me know!
Last edited on
Topic archived. No new replies allowed.