SDL with CodeBlocks

Hello,

I am trying to connect SDL to my CodeBlocks IDE, but I am receiving errors… I assume that it is a compiler issue or a save location issue, for I have followed a few tutorials and linked it correctly (as far as I know). If anyone can help me out with resolving this issue I would be very thankful.

Code:
-------------- Build: Debug in Tutorial1 (compiler: GNU GCC Compiler)---------------

x86_64-w64-mingw32-g++.exe -LC:\SDL2-devel-2.0.4-mingw\SDL2-2.0.4\i686-w64-mingw32\lib -o bin\Debug\Tutorial1.exe obj\Debug\src\Main.o -lmingw32 -lSDL2main -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: cannot open output file bin\Debug\Tutorial1.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 3 second(s))
2 error(s), 0 warning(s) (0 minute(s), 3 second(s))

Looks like the compiler cannot open the output file to write.

Check your permission in the output path.

I figured out how to get rid of the permission denied part. Hooray!!!

But now… I can’t get the SDL library to link up… [Evil or Very Mad]

Here is my debug log:

Code:

-------------- Build: Debug in Tutorial1 (compiler: GNU GCC Compiler)---------------

x86_64-w64-mingw32-g++.exe -LC:\SDL\SDL2-devel-2.0.4-mingw\i686-w64-mingw32\lib -o bin\Debug\Tutorial1.exe obj\Debug\src\Main.o -lmingw32 -lSDL2main -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
3 error(s), 0 warning(s) (0 minute(s), 1 second(s))

I do not understand why it is skipping where the libraries are, could anyone help me with this problem please?

Now, I see the Permission denied bit, and I know where that is found, but how do I proceed to give it permission?? [Crying or Very sad]

I have followed this Installation guide as well, and it still shows that I cannot find -lSDL or -lSDLmain.

If that is easy for you, and you’ll be using SDL2, just for compiling your programs, try this method:

-> Remove anything that has to do with SDL from Codeblocks/MinGW.

-> Download the mingw binaries from the SDL website

-> From the appropriate folder (x86, x64 or whatever they are called), do:

  • copy the contents of ‘include’ at ‘mingw/include/SDL2/’

  • copy the contents of ‘lib’ at ‘mingw/lib’

  • copy the contents of ‘bin’ at ‘mingw/bin’*

Then, you will be able to compile all SDL2 projects by doing the following:

#include SDL2 files like this:

#include “SDL2/SDL.h”

And add the following at the extra linker settings (note the order):

-lSDL2_main -lSDL2

Hope it helps,
Aggelos Kolaitis

  • Doing this means that you wont have to copy SDL2.dll at the same directory where the executable is. This could show errors, however, if you try to compile other people’s code. I mainly work under Linux, so that’s my setup which I use to test my code under Windows. Well, it works for me Smile

My Debug Log looks like this

Code:
-------------- Build: Debug in Tutorial1 (compiler: GNU GCC Compiler)---------------

x86_64-w64-mingw32-g++.exe -o bin\Debug\Tutorial1.exe obj\Debug\src\Main.o -lSDL2main -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/libSDL2main.a when searching for -lSDL2main
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0\libSDL2main.a when searching for -lSDL2main
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/lib/libSDL2main.a when searching for -lSDL2main
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/lib\libSDL2main.a when searching for -lSDL2main
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/libSDL2main.a when searching for -lSDL2main
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…\libSDL2main.a when searching for -lSDL2main
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/libSDL2main.a when searching for -lSDL2main
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/lib/libSDL2main.a when searching for -lSDL2main
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/libSDL2main.a when searching for -lSDL2main
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/libSDL2.dll.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/libSDL2.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0\libSDL2.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/lib/libSDL2.dll.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/lib/libSDL2.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/lib\libSDL2.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/libSDL2.dll.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/libSDL2.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…\libSDL2.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/libSDL2.dll.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/libSDL2.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/lib/libSDL2.dll.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/lib/libSDL2.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/libSDL2.dll.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/libSDL2.a when searching for -lSDL2
C:/TDM-GCC-64/bin/…/lib/gcc/x86_64-w64-mingw32/5.1.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
3 error(s), 0 warning(s) (0 minute(s), 1 second(s))> On Sep 5, 2013, at 9:41 AM, “Kaifory” wrote:

the “skipping incompatible” errors you are getting are because the libraries you are trying to link have the wrong architecture (e.g., 32bit vs 64bit). Just make sure that if you are compiling your program for 32bits, you link with the 32bits SDL libraries, and if you are compiling for a 64bit target, you are linking with the 64bit versions of the libraries.

Thank you very much for the help! The 64bit seems to make the difference for the libs. I feel that I am making progress, as now I only have one error! :smiley:

Here is my most recent build log. It says the SDL2.lib is in the wrong format? I’m not quite sure what the deal is, but if anyone could help me out with this one, hopefully my quest to set up SDL will be finished.

Code:
-------------- Build: Debug in Tutorial1 (compiler: GNU GCC Compiler)---------------

x86_64-w64-mingw32-g++.exe -LC:\SDL2-devel-2.0.4-mingw\SDL2-2.0.4\lib\x64 -o bin\Debug\Tutorial1.exe obj\Debug\src\Main.o -lSDL2 -lSDL2main
C:\SDL2-devel-2.0.4-mingw\SDL2-2.0.4\lib\x64/SDL2.lib: error adding symbols: File in wrong format
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
1 error(s), 0 warning(s) (0 minute(s), 1 second(s))

Good, glad that helped :slight_smile:

I don’t know how to fix this specifically. But from the info I read in this other post ( http://stackoverflow.com/questions/2527780/c-linker-error-sdl-image-could-not-read-symbols ), that problem is still caused by the same 32bit/64bit thing. Probably there is still some path somewhere that is incorrect in the project settings?

Hi,

I have done that. It is very straightforward.

But you have to understand about 32-bit and 64-bit.

On your first try make sure to only use everything in 32-bit version!!

Do not use any 64-bit lib or dll. It will work.

Hi,

Looks like you put the 32bit library file into the 64bit folder (or the otherway around).

Personally I use MSYS2, with the Mingw64 build of SDL2 that can be installed through its package manager (pacman). Alternatively I build SDL2 as a subproject with the CMAKE. Either way would prevent the problem from the mismatched version of dll/lib files.

Okay, I think I’m just going to restart… it seems that nothing is working. I have CodeBlocks (a recent version); I have TDM-GCC-32 (I also have the 64 version) compiler; I have downloaded SDL from libsdl.org using the SDL2 mingw dev package. Now all I need is a new-ish tutorial. The one on lazyfoo tutorial does not show the same folders as my folder has, and following still doesn’t work… any quality references would be much appreciated!

Also, if anybody could share how they have SDL2 set up, maybe it could work for me as well?

Thanks, lane

Okay, I think I have eliminated the whole 32 bit vs. 64 bit. I have uninstalled the 64bit compiler and only have the 32. I ran a ‘Hello World’ and it worked. I set up the include and lib folder in CodeBlocks. It recognizes SDL :slight_smile: I am now receiving an error I have not seen before.

Code:
-------------- Build: Debug in SettingUpSDL (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -g -IC:\SDL2 -IC:\SDL2 -c C:\Projects\SettingUpSDL\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LC:\SDL2-devel-2.0.4-mingw.tar\SDL2-devel-2.0.4-mingw\SDL2-2.0.4\i686-w64-mingw32\lib -LC:\SDL2-devel-2.0.4-mingw.tar\SDL2-devel-2.0.4-mingw\SDL2-2.0.4\i686-w64-mingw32\lib -o bin\Debug\SettingUpSDL.exe obj\Debug\main.o -lSDL2main -lSDL2
C:/TDM-GCC-32/bin/…/lib/gcc/mingw32/5.1.0/…/…/…/libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain at 16’
collect2.exe: error: ld returned 1 exit status

For my library linker, I have it set to -lSDL2main and -lSDL2. Has anyone else had this undefined reference to ‘WinMain at 16’?

I GOT IT TO WORK! I have SDL2 working in Code::Blocks!!! :smiley:

I would like to thank all of you that gave me advice on this horrendous set up. I got it running by simply restarting. I got the files once again, extracted, then set them up in the C:. I started a new console application project, and tested after every step of set up (putting in the include path, putting in the lib path, putting in the linker settings). Also I believe that the way you put in the ‘Linker Settings’ has to be in a specific order (-lmingw32 -lSDL2main -lSDL2), otherwise you get undefined reference errors. (oh and I also believe that I was receiving the Winmain error because of not setting up my main function properly: int main( int argc, char* args[] ) ).

Thank You All Very Much!,

lane