Pong

Started by
26 comments, last by Neoecs 18 years, 12 months ago
Sorry for bumping up an old thread, but when i compile the code

#include "SDL.h"int main(int argc, char *argv[]){    if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());        exit(1);    }    atexit(SDL_Quit);	{ SDL_Surface *screen;	   screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);	   if ( screen == NULL ) {	      fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());	      exit(1);	  }	}return 0;}


It wont work, I get the errors

--------------------Configuration: SDL_test - Win32 Debug--------------------
Compiling...
main.cpp
C:\Program\Microsoft Visual Studio\MyProjects\SDL_test\main.cpp(8) : error C2065: 'exit' : undeclared identifier
Error executing cl.exe.

SDL_test.exe - 1 error(s), 0 warning(s)


And when I comment away all the code betwen main{ and } it gives me the errors

--------------------Configuration: SDL_test - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
msvcrt.lib(MSVCRT.dll) : error LNK2005: _exit already defined in LIBCD.lib(crt0dat.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strncpy already defined in LIBCD.lib(strncpy.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _fclose already defined in LIBCD.lib(fclose.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __isctype already defined in LIBCD.lib(isctype.obj)
LIBCD.lib(crt0init.obj) : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_SetModuleHandle
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_Quit
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_GetError
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_Init
Debug/SDL_test.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.

SDL_test.exe - 9 error(s), 1 warning(s)

What hav I done wrong?

Thank you.
Advertisement
I think you need to include cstdlib to use the exit() function.
skulldrudgery--A tricky bit of toil
Quote:error C2065: 'exit' : undeclared identifier

#include <stdlib.h>

The rest of the errors are because you haven't linked SDL to your project.
Thank you! That helped some.. But.. What about "Cant execute Link.exe"?

--------------------Configuration: SDL_test - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
msvcrt.lib(MSVCRT.dll) : error LNK2005: _exit already defined in LIBCD.lib(crt0dat.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strncpy already defined in LIBCD.lib(strncpy.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _fclose already defined in LIBCD.lib(fclose.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __isctype already defined in LIBCD.lib(isctype.obj)
LIBCD.lib(crt0init.obj) : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_SetModuleHandle
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_Quit
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_GetError
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_Init
Debug/SDL_test.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.

SDL_test.exe - 9 error(s), 1 warning(s)
You need to link to the SDL library. What compiler are you using?
I am linking to the SDLmain.lib as said in the FAQ. (Still error.)
Link to SDL.lib too. Also, make sure (if you are using MSVC) to go to Properties->C/C++->Code Generation and make sure Multi-threaded DLL is selected
Ok, thatnk you. What should i link to in Dev-cpp?

This topic is closed to new replies.

Advertisement