I'm sorry, I'm a noob with SDL, but I'm having trouble just getting it to compile. But the thing is, the very first SDL project I ever made worked perfectly, and after following the same exact steps with my next one, ever since then I have had absolutely no success. Let me start from the beginning.
I used the tutorials at lazyfoo.net to set up SDL with VC++ 2008. My first project, as I said, worked fine. Afterwards, it kept saying I had no entry point. I think this means it can't find main() anywhere, but I have a main() function. I've made several other projects, all with the same issue, VC cannot find an entry point. So I right clicked main and went to its definition, and it turns out SDL has a #define for main to turn it into SDLMain. I'm guessing the real main has been hidden in the library because I can't find any source for it.
So then I tried MinGW. Again, one successful project, then it all crumbles. I will add that for some reason the source files I got from LF work perfectly, but mine give me a different error, that main() is making an undefined reference to 'WinMain@16' and then collect2 returns an exit status 1.
Tried with Bloodshed Dev C++, see MinGW story.
Code::Blocks, can't find main().
Can someone give me some detailed instructions or a link to them that may help point out what I'm doing wrong? I swear I followed LF's instructions to the letter, and I keep my VC and MinGW versions of SDL in separate directories. I am rather desperate to learn SDL. From what I've seen of it, it's the best C++ library I've seen, and I feel so comfortable with how it works. I've tried several other devkits, and this one really strikes a good cord with me, so please, if anyone can help, I would be forever grateful.
8 replies to this topic
#1
Posted 04 December 2011 - 07:28 PM
Leafly Forums, a place for game designers and players alike.
|
|
|
#2
Posted 05 December 2011 - 12:21 AM
Can you please provide the code that doesn't compile.
As a guess though, I'd say you used the lazy main definition:
As a guess though, I'd say you used the lazy main definition:
// lazy one
int main() {
}
// one that SDL wants
int main(int argc, char* argv[]) {
}
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#3
Posted 05 December 2011 - 03:08 AM
The WinMain@ issue is likely the toolchain not being able to determine where the entry point of the application is.
If you set up a main() signature that SDL's library/macros recognise (as FlyingDutchman has pointed out) then you can in MinGW link it with -lmingw32 -lSDLmain -lSDL and any other libraries you required to compile it.
I will attempt to make a proof of concept on my Windows XP machine tomorrow (I believe I have done it a few times in the past) when I wake up if you have no luck causing it to work.
Alexander.
If you set up a main() signature that SDL's library/macros recognise (as FlyingDutchman has pointed out) then you can in MinGW link it with -lmingw32 -lSDLmain -lSDL and any other libraries you required to compile it.
I will attempt to make a proof of concept on my Windows XP machine tomorrow (I believe I have done it a few times in the past) when I wake up if you have no luck causing it to work.
Alexander.
Edited by Alexander, 05 December 2011 - 03:40 AM.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#4
Posted 10 December 2011 - 03:41 PM
This is my code:
I copy this into a new project, it fails. But the first time it worked.
//Include
#include "SDL.h"
#include "SDL_image.h"
#include <string>
//Declarations
#define SCREEN_W 320
#define SCREEN_H 240
#define SCREEN_B 32
#define APP_NAME "SDL"
typedef SDL_Surface img;
typedef SDL_Rect Rec;
img* screen;
img* hello;
SDL_Event* Event;
//Prototypes
bool init();
void drawImage(int x, int y, SDL_Surface* source, SDL_Surface* destination);
img* loadImage(std::string filename);
int main( int argc, char* args[] )
{
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Set up the screen
screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, SCREEN_B, SDL_SWSURFACE);
//Load image
hello = loadImage("red_strip36.bmp");
//Draw image
SDL_BlitSurface(hello, 0, screen, 0);
//Refresh screen
SDL_Flip(screen);
//Pause
SDL_Delay(2000);
//Free surface
SDL_FreeSurface(hello);
//Quit SDL
SDL_Quit();
return 0;
};
///////////////////
//OTHER FUNCTIONS//
///////////////////
bool init(){
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
//Set up the screen
screen = SDL_SetVideoMode( SCREEN_W, SCREEN_H, SCREEN_B, SDL_SWSURFACE );
//If there was an error in setting up the screen
if( screen == NULL )
{
return false;
}
//Set the window caption
SDL_WM_SetCaption(APP_NAME, NULL);
//If everything initialized fine
return true;
};
void drawImage( int x, int y, SDL_Surface* source, SDL_Surface* destination ){
//Temporary rectangle to hold the offsets
Rec offset;
//Get the offsets
offset.x = x;
offset.y = y;
//Blit the surface
SDL_BlitSurface( source, NULL, destination, &offset );
};
img* loadImage( std::string filename ){
//The image that's loaded
img* loadedImage = NULL;
//The optimized image that will be used
img* optimizedImage = NULL;
//Load the image
loadedImage = IMG_Load( filename.c_str() );
//If the image loaded
if( loadedImage != NULL )
{
//Create an optimized image
optimizedImage = SDL_DisplayFormat( loadedImage );
//Free the old image
SDL_FreeSurface( loadedImage );
}
//Return the optimized image
return optimizedImage;
};
I copy this into a new project, it fails. But the first time it worked.
Leafly Forums, a place for game designers and players alike.
#5
Posted 10 December 2011 - 04:55 PM
I had:
It seemed to run fine afterwards. I am not sure the MSVC setup would be too difficult if you wish to go that route, after you set up how I have.
Alexander.
- Installed SDL development libraries (for mingw) and SDL_image development libraries(for VC) in to C:\mingw
- Had moved the contents of the C:\mingw\includes\sdl folder to C:\mingw\includes so that it could be read properly
- Had placed SDL_image.dll from the development library package in to C:\Windows as it wouldn't run without it (runtime)
- Compiled with this line:
g++ -Wall -o foo.exe foo.cxx -lmingw32 -lSDLmain -lSDL -lSDL_image
It seemed to run fine afterwards. I am not sure the MSVC setup would be too difficult if you wish to go that route, after you set up how I have.
Alexander.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#6
Posted 21 December 2011 - 04:48 PM
Alexander said:
I had:
- Installed SDL development libraries (for mingw) and SDL_image development libraries(for VC) in to C:\mingw
- Had moved the contents of the C:\mingw\includes\sdl folder to C:\mingw\includes so that it could be read properly
- Had placed SDL_image.dll from the development library package in to C:\Windows as it wouldn't run without it (runtime)
- Compiled with this line:
g++ -Wall -o foo.exe foo.cxx -lmingw32 -lSDLmain -lSDL -lSDL_imageIt seemed to run fine afterwards. I am not sure the MSVC setup would be too difficult if you wish to go that route, after you set up how I have.Alexander.
Leafly Forums, a place for game designers and players alike.
#7
Posted 21 December 2011 - 04:56 PM
-Wall shows all warnings.
I've copied your code and it works fine, even after several compiles.
I've copied your code and it works fine, even after several compiles.
A conclusion is where you got tired of thinking.
#define class struct // All is public.
#8
Posted 28 December 2011 - 05:50 PM
Flying Dutchman said:
-Wall shows all warnings.
I've copied your code and it works fine, even after several compiles.
I've copied your code and it works fine, even after several compiles.
Leafly Forums, a place for game designers and players alike.
#9
Posted 28 December 2011 - 08:42 PM
Try to reinstall the IDE. If that doesn't work, try to compile it manually - if you haven't already.
A conclusion is where you got tired of thinking.
#define class struct // All is public.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









