Share via


error C3861: 'exit': identifier not found

Question

Monday, March 27, 2006 1:07 PM

Hi,

I'm trying to build an old code (main.cpp) where I'm using SDL.  This is my first time using Visual Studio 2005.

I have included the following:

#include <SDL/SDL.h>

#include <stdio.h>

#include <stdlib.h>

 

int main(int argc, char *argv[])

{

if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )  //SDL_Init will return -1 if it could not initialize

{

printf("Unable to init SDL: %s\n", SDL_GetError());

exit(1);

}

atexit(SDL_Quit);

}

I get the error :   error C3861: 'exit': identifier not found.

What am I doing wrong?

 

All replies (11)

Monday, March 27, 2006 4:05 PM ✅Answered

That is very strange.

The following compiles perfectly with VC++ 2005 :

#include <stdlib.h>

int main()
{
exit(0);
}

Could you try compiling the above code snippet?

 icesun wrote:

Hi,

I'm trying to build an old code (main.cpp) where I'm using SDL.  This is my first time using Visual Studio 2005.

I have included the following:

#include <SDL/SDL.h>

#include <stdio.h>

#include <stdlib.h>

 

int main(int argc, char *argv[])

{

if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 )  //SDL_Init will return -1 if it could not initialize

{

printf("Unable to init SDL: %s\n", SDL_GetError());

exit(1);

}

atexit(SDL_Quit);

}

I get the error :   error C3861: 'exit': identifier not found.

What am I doing wrong?

 


Monday, March 27, 2006 6:07 PM ✅Answered

Another technique is to generate a preprocessor output file for the cpp file being compiled.  Under C/C++ settings, set the Generate Preprocessed File (/P) to Yes.  Then look for the definition of exit().  If it is isn't there, then compare with stdlib.h to see how it might have been #ifdef'd out.

Brian

 


Tuesday, March 28, 2006 8:23 PM ✅Answered

I tried to understand the main.i file, but didn't ...

then I looked through the stdlib.h file, and found the the following line was commended out:

_CRTIMP __declspec(noreturn) void __cdecl exit(__in int _Code);

I took out the comment and recompiled it ... and now it works.

Thank you both for your help


Tuesday, March 28, 2006 10:29 AM

Hi Nishant.

I tried compiling the above snipplet, but got the same error.

When I create the new project I make it as a Windows 32 Console Application.

 


Tuesday, March 28, 2006 1:54 PM

Brian,

I get a LINK error, when I try this ...

cannot open file '.\Debug\main.obj'


Tuesday, March 28, 2006 3:01 PM

 icesun wrote:

Hi Nishant.

I tried compiling the above snipplet, but got the same error.

When I create the new project I make it as a Windows 32 Console Application.

 

Put the code into a cpp file (say a.cpp)

#include <stdlib.h>

int main()
{
exit(0);
}

And compile from the command line. Use cl a.cpp

Does that work?

 


Tuesday, March 28, 2006 3:20 PM

Sorry, I forgot to mention.  The purpose here is not to build, but rather to diagnose. /P will generate main.i, which will be a long file.  This is where the actual results of the inclusion of stdlib.h is revealed and may lend clues as to why exit is not being declared.


Tuesday, March 28, 2006 5:01 PM

No,

I'm not able to compile from the command line ... 'cl' is not recognized.


Tuesday, March 28, 2006 5:07 PM

 icesun wrote:

No,

I'm not able to compile from the command line ... 'cl' is not recognized.

Use the Visual Studio 2005 Command Prompt.


Tuesday, March 28, 2006 7:56 PM

No,

get the same error:

a.ccp(5) : error c3861: 'exit': identifier not found.


Tuesday, March 28, 2006 7:58 PM

Note: i followed up with your question about how to use /P earlier in this thread. Perhaps this is another avenue worth trying.