stdlib.h: no such file or directory

For anyone who landed here trying to compile a C++ program with Cygwin on Windows, my problem was that I had both MingW and Cygwin. MingW was installed as part of the Cygwin setup. I used the setup.exe (let's call it package installer) from Cygwin and removed all instances of MingW. After that, my test application compiled properly.

Note: This solution is what worked for me. There are gazillion other reasons why you have the same error.


Your error appears to stem from including linux/time.h when also trying to include stdlib.h. linux/time.h is a kernel header and should only be used in kernel code. stdlib.h is a user-land function and should only be used in user programs. If you notice the error you get:

/usr/include/linux/time.h:12: error: redefinition of 'struct timespec'
/usr/include/linux/time.h:18: error: redefinition of 'struct timeval'

you can see that you are getting an error related to this. As seen in your long trace, this is because stdlib.h is including time.h (the one in /usr/include, not /usr/include/linux). I imagine that this is the real cause of the error you see about not finding stdlib.h (although I cannot imagine the details of how the errors are occurring the way they are).