SDL avec codeBlocks et MS VcToolkit 2003
Bonjour,
Je d�sire utiliser la librairie SDL via l'IDE codeBlocks avec le compilateur VC ToolKit 2003.
Apr�s de multiples essais, impossible d'utiliser la librairie (probl�mes de linkage ou de param�trage).
Voici la description de mon install :
I ] Les repertoires d'installation des composants :
1 ) Codeblocks (sans MingGw) :
path : C:\CodeBlocks
2 ) VcToolkit 2003 :
path : C:\VCToolkit2003
3 ) .NET 1.1 SDK :
path : C:\Program Files\Microsoft.NET\SDK\v1.1
4 ) Platform SDK :
path : C:\PlatformSDK
5 ) DirectX SDK :
path : C:\dxsdk
II ] Les param�tres dans codeBlocks :
1 ) Menu "Settings" > "compiler" > onglet "directories" > sous onglet "compiler" :
- C:\VCToolkit2003\include
- C:\PlatformSDK\Include
- C:\Program Files\Microsoft.NET\SDK\v1.1\include
- C:\dxsdk\Include
1.1 ) Menu "Settings" > "compiler" > onglet "directories" > sous onglet "linker" :
- C:\VCToolkit2003\lib
- C:\Program Files\Microsoft.NET\SDK\v1.1\Lib
- C:\PlatformSDK\Lib
- C:\dxsdk\Lib
2 ) Menu "Settings" > "compiler" > onglet "programs" :
> compiler installation directory :
path : C:\VCToolkit2003\
2.1 ) Menu "Settings" > "compiler" > onglet "programs" > sous onglet "Program Files" :
- c compiler : cl.exe (situ� dans : C:\VCToolkit2003\bin)
- c++ compiler : cl.exe (situ� dans : C:\VCToolkit2003\bin)
- linker for dynamic libs : link.exe (situ� dans : C:\VCToolkit2003\bin)
- linker for static libs : link.exe (situ� dans : C:\VCToolkit2003\bin)
- ressource compiler : RC.Exe (situ� dans : C:\PlatformSDK\Bin)
- Make Program : nmake.exe (situ� dans : C:\PlatformSDK\Bin)
2.1 ) Menu "Settings" > "compiler" > onglet "programs" > sous onglet "Other" :
- compiler logging : Full command line
- build method : Invoke compiler directly
- Shell to run console programs : xterm -T $TITLE -e
2.2 ) param�tres SDL :
- fichiers ".h" : C:\VCToolkit2003\include\sdl\
- fichier "SDL.lib" : C:\VCToolkit2003\lib\SDL.lib
- fichier "SDLmain.lib" : C:\VCToolkit2003\lib\SDLmain.lib
III ] Mon projet SDL
1 ) Projet g�n�r� avec le template SDL de codeBlocks (avec creation automatique de fichier "main.cpp")
2 ) Param�tres du projet :
- Nom du projet : "sdlapp" (C:\projHuit\sdlapp.cbp)
- r�pertoire du projet et des sources : C:\projHuit (contenant "SDL.dll")
- Type : "GUI Apllication"
- Output File name : "sdlapp.exe"
- Execution Working Dir : "."
- Objects Output Dir : ".objs" (situ� dans : C:\projHuit)
- Files : "main.cpp" (situ� dans : C:\projHuit), "cb.bmp" (situ� dans : C:\projHuit)
2.1 ) Target Build Options :
- selected compiler : Microsoft Visual C++ 2003
- policy : "append target options to project options"
- onglet "compiler flags" : "disable optimisation" coch� uniquement
- policy : "append target options to project options"
- onglet "linker" > "link libraries" : "SDL" & "SDLmain"
- policy : "append target options to project options"
- onglet "directories" > "compiler" : policy : "append target options to project options"
- onglet "directories" > "linker" > : policy : "append target options to project options"
- onglet "directories" > "ressource compiler" > : policy : "use project options only"
- onglet "commands" et "custom variables" : vides
IV ] Le fichier "main.cpp" g�n�r� par codeBlocks (code complet) :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif
#include <sdl/SDL.h>
/*#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif
*/
int main ( int argc, char** argv )
{
// initialize SDL video
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}
// make sure SDL cleans up before exit
atexit(SDL_Quit);
// create a new window
SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16,
SDL_HWSURFACE|SDL_DOUBLEBUF);
if ( !screen )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
return 1;
}
// load an image
SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
if (!bmp)
{
printf("Unable to load bitmap: %s\n", SDL_GetError());
return 1;
}
// center the bitmap on screen
SDL_Rect dstrect;
dstrect.x = (screen->w - bmp->w) / 2;
dstrect.y = (screen->h - bmp->h) / 2;
// program main loop
bool done = false;
while (!done)
{
// message processing loop
SDL_Event event;
while (SDL_PollEvent(&event))
{
// check for messages
switch (event.type)
{
// exit if the window is closed
case SDL_QUIT:
done = true;
break;
// check for keypresses
case SDL_KEYDOWN:
{
// exit if ESCAPE is pressed
if (event.key.keysym.sym == SDLK_ESCAPE)
done = true;
break;
}
} // end switch
} // end of message processing
// DRAWING STARTS HERE
// clear screen
SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
// draw bitmap
SDL_BlitSurface(bmp, 0, screen, &dstrect);
// DRAWING ENDS HERE
// finally, update the screen :)
SDL_Flip(screen);
} // end main loop
// free loaded bitmap
SDL_FreeSurface(bmp);
// all is well ;)
printf("Exited cleanly\n");
return 0;
} |
VI ] Build Logs :
Project : sdlapp
Compiler : Microsoft Visual C++ Toolkit 2003 (called directly)
Directory : C:\projects\projHuit\
--------------------------------------------------------------------------------
Switching to target: default
cl.exe /nologo /Od /Od /W3 /W4 /W3 /IC:\VCToolkit2003\include /IC:\PlatformSDK\Include /I"C:\Program Files\Microsoft.NET\SDK\v1.1\include" /IC:\dxsdk\Include /c main.cpp /Fo.objs\main.obj
main.cpp
cl : Command line warning D4025 : overriding '/W3' with '/W4'
cl : Command line warning D4025 : overriding '/W4' with '/W3'
link.exe /nologo /subsystem:windows /LIBPATH:C:\VCToolkit2003\lib /LIBPATH:"C:\Program Files\Microsoft.NET\SDK\v1.1\Lib" /LIBPATH:C:\PlatformSDK\Lib /LIBPATH:C:\dxsdk\Lib /out:sdlapp.exe SDLmain.lib SDL.lib .objs\main.obj /NODEFAULTLIB:msvcrt.lib
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol _exit imported in function _main
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol __iob imported in function _ShowError
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol _fclose imported in function _cleanup_output
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol __pctype imported in function _ParseCommandLine
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol ___mb_cur_max imported in function _ParseCommandLine
SDLmain.lib(SDL_win32_main.obj) : warning LNK4217: locally defined symbol __isctype imported in function _ParseCommandLine
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__strrchr referenced in function _main
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__fprintf referenced in function _ShowError
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__remove referenced in function _cleanup_output
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__fopen referenced in function _cleanup_output
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__fgetc referenced in function _cleanup_output
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__setbuf referenced in function _WinMain@16
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__setvbuf referenced in function _WinMain@16
SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol __imp__freopen referenced in function _WinMain@16
sdlapp.exe : fatal error LNK1120: 8 unresolved externals
Process terminated with status 1 (0 minutes, 2 seconds)
9 errors, 6 warnings
VII ] Question :
Mes param�tres semblent de linkage corrects d'ou peux provenir l'erreur, quelles sont les pistes � explorer ?
Merci d'avance (ps : mon choix se porte uniquement sur le compilateur Microsoft... pour l'instant)
:cry:
Quelle sont les lib manquantes ?
Merci pour ta r�ponse
De quelles librairies s'agit-il ?
msvcrt.lib, msvcprt.lib ?
en cherchant depuis trois jours j'ai trouv� ces infos :
http://root.cern.ch/root/Procedure/P...Visual%20C.htm
j'ai t�l�charg� la lib trouv�e sur cette page (en l'occurence "msvcprt.lib") mais qui ne semble pas utilisable en l'�tat : un fichier "msvcprt.def" est disponible pour g�n�rer un fichier "msvcprt.lib" utilisable, mais la proc�dure m'�chappe.
Des infos compl�mentaires seraient les bienvenues, en effet je rencontre un probl�me similaire avec d'autres librairies (en l'occurence celle du framework kjAPI) qui semble aussi n�cessiter le multithread.
Je pense qu'il pourrait �tre salutaire de r�diger un tutorial clair et complet sur ce probl�me qui concerne tous les utilisateurs de codeblocks avec le compilateur vc++ toolkit 2003. C'est une t�che � laquelle je serais enchant� de m'atteller d�s que je pourrais r�soudre le probl�me pos� par ces libs manquantes.
Merci d'avance.
:)