For some reason, I keep getting undefined reference to `SDL_main’, in my code below.
void init(SDL_Window*&, SDL_Renderer*&, SDL_Joystick*&, int, int);
void exit(SDL_Window*&, SDL_Renderer*&, SDL_Joystick*&);
int main(int argc, char **argv)
//screen resolution (allow user to modify later)
static const int SCREEN_WIDTH = 1024;
static const int SCREEN_HEIGHT = 768;
SDL_Window* window = NULL; //make window
SDL_Renderer* renderer = NULL;// make renderer
SDL_Joystick* gameController = NULL; //make controller
//initialize SDL 2
init(window, renderer, gameController, SCREEN_WIDTH, SCREEN_HEIGHT);
World1 world(SCREEN_WIDTH, SCREEN_HEIGHT, renderer);
//exit SDL 2 and end program
exit(window, renderer, gameController);
Are my main function arguments incorrect? I thought I installed SDL correctly in my project (search directories, additional linker options, dlls). What could be the issue?
Also, I included <SDL.h> in game.h. Here is game.h:
#include <SDL.h> //for SDL 2.0.5
#include <SDL_image.h> //for SDL_image 2.0.1
#include "worlds.h" //for game worlds
using namespace std;
//SDL start and exit function prototypes
#endif // GAME_H_INCLUDED
Hello there and welcome to the forum!
I can’t see in your code that you’re actually including
Are you including that in
The error might also be caused by an incorrect entrypoint signature.
Your entrypoint has the following signature:
int main(int argc, char **argv)
SDL_main entrypoint has the following signature:
int main(int argc, char* argv)
Check that you’re including SDL at the top of your application, then try to match your entrypoint with the built-in one and then see if it solves the problem.
Yes, <SDL.h> is in game.h. Changing the function signature led to the same error. Let me know of any other solutions you may have.
What IDE/compiler are you using?
Check your linking and include settings.
I am using the MinGW compiler with Code::Blocks 17.12.
If I right click on my project, select properties, then Build Options, here are my settings:
Other linker options box: -lmingw32 -lSDL2main -lSDL2 -lSDL2_image
Search Directories (Compiler): D:\Programs\Programming\Tools\SDL 2\SDL2_image-2.0.5\i686-w64-mingw32\include\SDL2
Search Directories (Linker): D:\Programs\Programming\Tools\SDL 2\SDL2_image-2.0.5\i686-w64-mingw32\lib
Also, here is an image of my project’s directory structure, where I put my dlls:
Does anything look wrong with this? What other insights do you or does anyone have?
Sorry, I haven’t used MinGW and/or Code::Blocks so I can’t help you with its settings. I use Visual Studio as IDE and actually compiled the code that you’ve shown in this thread, and I didn’t have any issues compiling it.
I do use MinGW (but not Code::Blocks) and I can’t see anything obviously wrong with the OP’s settings. The only thing different from mine is that I specify the compiler search path without the final
\SDL2 and I include the header with
#include "SDL2/SDL.h". But I can’t see that this would make any difference.
Ok, well, I originally built this in Visual Studio. I was trying to convert this project to Code::Blocks, and in the process, I copy and pasted all the code at once and added all the files at once. Today, I retried and slowly added all the files, headers, and classes in multiple steps, not moving forward UNTIL the project was successfully built.
Now, it works. I’m not sure what the issue was exactly, but adding too much at once messed things up somehow.
Glad to hear that you got the issue solved.
Good luck with your project!