Help! SDL Setup -> Undefined References! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

Help! SDL Setup -> Undefined References!

lazyfoo.net/tutorials/SDL/01_hello_SDL/windows/codeblocks/index.php I am currently using this tutorial to set up SDL libraries and headers in CodeBlocks. I completed all the steps for a project, created a new file, and wrote some simple code. Compiling using F9 gives me the following errors: In SDL_main(): ... Undefined reference to SDL_Init(); ... Undefined reference to SDL_CreateWindow(); ... ... Undefined reference to "WinMain@16" Why do I get these? And how can I solve these?

15th Jul 2017, 4:30 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
18 Answers
+ 8
this error usually means codeblocks can not find sdl. see step 5
15th Jul 2017, 5:16 AM
jay
jay - avatar
+ 8
oooooooo visual studio seems the go i guess
16th Jul 2017, 11:03 AM
jay
jay - avatar
+ 6
just to clarify, you are using windows right
15th Jul 2017, 8:27 AM
jay
jay - avatar
+ 6
is your main function look like: int main(int argc, char* args[])
15th Jul 2017, 8:30 AM
jay
jay - avatar
+ 6
😭 must be a way.. i was using it on linux just fine.. did you get the mingw sdl development files?
16th Jul 2017, 10:45 AM
jay
jay - avatar
+ 5
repeating a skipped step is usually enough to resolve the issue. each section that you can mess up has a little blurb on what errors you might get if it was not done correctly. sure it could be more though
15th Jul 2017, 8:18 AM
jay
jay - avatar
+ 5
http://forums.libsdl.org/viewtopic.php?p=49618 this guy describes your exact issue
15th Jul 2017, 8:46 AM
jay
jay - avatar
+ 4
@Kinshuk You are using SDL as well? Nice! Are you using SDL1 or SDL2?
15th Jul 2017, 5:10 AM
Manual
Manual - avatar
+ 4
@Jay is good with SDL2
15th Jul 2017, 5:10 AM
Manual
Manual - avatar
+ 4
How many codes are tied to that function? edit How many dependencies does it have? where should it have been defined?
15th Jul 2017, 5:11 AM
Manual
Manual - avatar
+ 4
@jay I think I have messed up the linker step, as the program is complaining of undefined references. But why hasn't lazy foo described solutions for the messing up problems?
15th Jul 2017, 8:14 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 4
@Manual Right now, just one code file. Its just a test code. I usually use SDL 2 on VS, but I wished to use it on CodeBlocks as well...
15th Jul 2017, 8:19 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 4
@Jay I tried repeating the steps again and again, but still can't solve the problem. It seems the SDL_main() is clashing with the WinMain, and the compiler still believes WinMain to be the application's entry point. //Perhaps that is the reason I get the last error as: //undefined reference to WinMain@16 ? I think Ill have to temporarily disable it, but I don't know how...
15th Jul 2017, 8:21 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 4
@jay Yes, thats how my main looks like this now. I am trying to use SDL in CodeBlocks on Windows right now... Sorry for the linux confusion, that was a typo...
15th Jul 2017, 8:32 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 4
there are a few thing here u could try: https://wiki.libsdl.org/FAQWindows
15th Jul 2017, 8:33 AM
jay
jay - avatar
+ 4
Where do I write this: sdf-config --libs??
15th Jul 2017, 8:36 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 4
The problem, still exists... 😢 I guess there is no solution then except shifting back to VS...
16th Jul 2017, 10:36 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 3
@jay Yes, I did, But to no avail.
16th Jul 2017, 10:56 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar