tags:

views:

77

answers:

2

I get these errors after issuing a g++ command on a .cpp file: error: ‘exit’ was not declared in this scope error: ‘printf’ was not declared in this scope

The problem is that when I compiled this program on another linux machine, everything went fine. I tried searching around, but all I found was that I need to include files like 'stdlib.h'.

Could it be I'm missing some library on my OS? If so, what might it be?

+3  A: 

Recent versions of GCC have gotten stricter in what responsibilities the programmer needs to fulfill. Include the cstdlib, cstdio, etc. header and access these functions from the std namespace.

Ignacio Vazquez-Abrams
#include <sys/wait.h>#include <iostream>using namespace std;This is the current header. Somehow it works with just this on other Linux OS, and I need to find out how. Adding extra headers to this is not an option at the moment.
Max
Then compiling it under recent versions of GCC is *also* not an option at the moment. Your call.
Ignacio Vazquez-Abrams
Hmm, alright. Is there any way to circumvent this? Maybe install something somewhere or change some parameters? Do you have any idea between what versions of gcc this change occurred?
Max
I don't know why you'd want to circumvent the standards. I mean, that just sounds silly... http://gcc.gnu.org/gcc-4.3/porting_to.html http://gcc.gnu.org/gcc-4.4/porting_to.html
Ignacio Vazquez-Abrams
Thank you very much. I know its kind of a weird thing to do, but it would make my life easier if I could, so I'd go out of my way to do it.
Max
If you look at section 3 of the man pages, each page lists the header that a function is defined in. If you're using the function but not including the header (or the C++ equivalent), then, to put it in the vernacular, "ur doin it rong".
Ignacio Vazquez-Abrams
+2  A: 

If you are in need of a quick (and dirty) fix try:

using namespace std;

Also make sure you are including the appropriate io headers.

shuttle87