Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ on Linux not recognizing commands like exit() and printf()

Tags:

c++

linux

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?

like image 569
Max Avatar asked Oct 18 '10 04:10

Max


2 Answers

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.

like image 194
Ignacio Vazquez-Abrams Avatar answered Oct 18 '22 15:10

Ignacio Vazquez-Abrams


Specifically for ‘exit’ was not declared in this scope all you need is:

#include <stdlib.h> 
like image 31
Mike S Avatar answered Oct 18 '22 14:10

Mike S