error C3861: 'exit': identifier not found

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



Answer this question

error C3861: 'exit': identifier not found

  • Jurgen

    No,

    get the same error:

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


  • Sherley Lee

    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



  • Ken Hizer

    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



  • rgallazzi

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

    icesun wrote:

    No,

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

    Use the Visual Studio 2005 Command Prompt.



  • Alberto Grasso

    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


  • Pranky

    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

     


  • MSpencer

    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.


  • Zone

    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.
  • Udi Dahan

    Brian,

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

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


  • dlevy1

    No,

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


  • error C3861: 'exit': identifier not found