Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: SDL + CodeBlocks = ??? [Help Setting Things Up...]  (Read 694 times)

KrazENooB

  • Escaped Lunatic
    • View Profile
SDL + CodeBlocks = ??? [Help Setting Things Up...]
« on: August 11, 2013, 06:54:14 pm »

So, this goes out to all you code monkeys, and game devs. I am trying to set up my CodeBlocks with SDL. To no avail, I have followed every tutorial, most of which are dated, or old, or leave HUGE bits of information out, I have tried problem solving on my own, even going through this step, by step, line by line, file.. by file..

I can not tell you how tedious that was. I have tried.

So, I ask of you, does anyone here use CodeBlocks and SDL, or have ANY idea how I would set up my linker settings to WORK...

The closest I have gotten was today, and STILL even the simplest of "Hello World" comes back fine, all but a "undefined reference to winmain@16" error, to which shows the orgin IN my main compiler, the default minGW32...

I am lost guys, someone, someone please help me...
Logged

Moghjubar

  • Bay Watcher
  • Science gets you to space.
    • View Profile
    • Demon Legend
Re: SDL + CodeBlocks = ??? [Help Setting Things Up...]
« Reply #1 on: August 11, 2013, 07:12:41 pm »

So wait, in a basic program you are getting errors or only when you try to link with SDL?

In any case, SDL and Codeblacks is exactly what I use, so I can help you set it up, and show you what resources I used to learn it.   If you want more of a stream to chat, PM me and I'll get on an IRC with you.
Logged
Steam ID
Making things in Unity
Current Project: Demon Legend
Also working on THIS! Farworld Pioneers
Mastodon

simoroth

  • Bay Watcher
    • View Profile
    • Maia
Re: SDL + CodeBlocks = ??? [Help Setting Things Up...]
« Reply #2 on: August 11, 2013, 07:16:59 pm »

Quote
So, I ask of you, does anyone here use CodeBlocks and SDL, or have ANY idea how I would set up my linker settings to WORK...

Yep.

Is your main function of the form:

Code: [Select]
int main(int argc, char* argv[])
Because it needs to be!

Edit... From the FAQ:

Quote
I get "Undefined reference to 'SDL_main'" ...

Make sure that you are declaring main() as:

#include "SDL.h"

int main(int argc, char *argv[])

You should be using main() instead of WinMain() even though you are creating a Windows application, because SDL provides a version of WinMain() which performs some SDL initialization before calling your main code. If for some reason you need to use WinMain(), take a look at the SDL source code in src/main/win32/SDL_main.c to see what kind of initialization you need to do in your WinMain() function so that SDL works properly.

I get "Undefined reference to 'WinMain@16'"

Under Visual C++, you need to link with SDLmain.lib. Under the gcc build environments including Dev-C++, you need to link with the output of "sdl-config --libs", which is usually: -lmingw32 -lSDLmain -lSDL -mwindows
« Last Edit: August 11, 2013, 07:18:46 pm by simoroth »
Logged
Making Maia; a space colony management sim: http://www.bay12forums.com/smf/index.php?topic=118473.0

KrazENooB

  • Escaped Lunatic
    • View Profile
Re: SDL + CodeBlocks = ??? [Help Setting Things Up...]
« Reply #3 on: August 11, 2013, 08:43:15 pm »

@simoroth

Yes, I made sure my test code had that included, what drove me up the wall however is even after I removed all SDL components and wrote a simple hello world, It still gave me the error, so I am certain something happened to my minGW32....

C++, minGW32, and Windows64 just seem to hate each other...

Mind you guys, of course I am new to this. Which is why I don't really understand whats going on.
Logged

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: SDL + CodeBlocks = ??? [Help Setting Things Up...]
« Reply #4 on: August 12, 2013, 08:56:55 am »

If you could use Linux, that'd probably solve your problems... at least part of them.

Also, are your libraries included in the correct order? I recall that there needed to be a specific one for linking, or else bad stuff would happen. I think the stuff that depends on other stuff needs to come last.