Author Topic: Solution for Code::Blocks 20.03 and SDL2 wizard project using mingw  (Read 623 times)

lorwerth

  • Guest
It's been some time since I used Code::Blocks, because I was developing exclusively for Linux. But now I'm returning to Windows and I see there are some nice changes. Thanks for the ongoing development. So far I'm pleased with the latest version.

Here are some results from building the SDL2 example. The first shows the wrong way. The second shows the right way. But as I mention below, it does require hand-copying sdl2.dll to the same directory as the exe file (bin/debug).

This may be informative for people who are struggling with this example. I spent several hours on this, but after getting a few hours of sleep it turned out to be easy to solve.

I did a clean install of Code::Blocks 20.03. I'm using the default setup, without any fiddling with the Code::Blocks settings. Before installing Code::Blocks, I deleted my existing mingw32 and mingw64 installations and let Code::Blocks do its default mingw installation. Code::Blocks has a feature to autodetect the compiler path. I verified the setup by building the example console and Windows GUI programs. No problems.

I also did a clean install of sdl2. The link is https://github.com/libsdl-org/SDL/releases/tag/release-2.26.0. Scroll down to Assets. I selected SDL2-devel-2.26.0-mingw.tar.gz. I downloaded, then extracted to c:\sdl2.

First, just a small comment on the source file for the SDL2 example. I changed $include <SDL.h> to #include <SDL2/SDL.h>. Otherwise, I'm not modifying the example source code.

Next I tried building the sdl2 example. In the dialog box, it asks for the sdl2 path,which I set to c:\sdl2\sdl2-2.26.0\i686_w64-mingw32. In this example, it is not correct to use the i686 option (32-bit). I've seen some old tutorials where this is the way they do it. People still refer to old tutorials. Here is the Build Log from that attempt.


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

g++.exe -Wall -g -IC:\sdl2\SDL2-2.26.0\i686-w64-mingw32\include -c C:\Users\David\winprogs\sdl_tests\sdlx1\main.cpp -o obj\Debug\main.o
g++.exe -LC:\sdl2\SDL2-2.26.0\i686-w64-mingw32\lib -o bin\Debug\sdlx1.exe obj\Debug\main.o   -lmingw32 -lSDL2main -lSDL2.dll -luser32 -lgdi32 -lwinmm -ldxguid
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\sdl2\SDL2-2.26.0\i686-w64-mingw32\lib/libSDL2main.a when searching for -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\sdl2\SDL2-2.26.0\i686-w64-mingw32\lib\libSDL2main.a when searching for -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\sdl2\SDL2-2.26.0\i686-w64-mingw32\lib/libSDL2main.a when searching for -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\sdl2\SDL2-2.26.0\i686-w64-mingw32\lib/libSDL2.dll.a when searching for -lSDL2.dll
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\sdl2\SDL2-2.26.0\i686-w64-mingw32\lib\libSDL2.dll.a when searching for -lSDL2.dll
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\sdl2\SDL2-2.26.0\i686-w64-mingw32\lib/libSDL2.dll.a when searching for -lSDL2.dll
C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2.dll
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 3 second(s))
3 error(s), 0 warning(s) (0 minute(s), 3 second(s))
 

When I try building another SDL2 project using the wizard, and set the path to x86_64-w64-mingw32 (64-bit), I get the following Build Log messages.


-------------- Clean: Debug in sdlz (compiler: GNU GCC Compiler)---------------

Cleaned "sdlz - Debug"

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

g++.exe -Wall -g -IC:\sdl2\SDL2-2.26.0\x86_64-w64-mingw32\include -c C:\Users\David\winprogs\sdl_tests\sdlz\main.cpp -o obj\Debug\main.o
g++.exe -LC:\sdl2\SDL2-2.26.0\x86_64-w64-mingw32\lib -o bin\Debug\sdlz.exe obj\Debug\main.o   -lmingw32 -lSDL2main -lSDL2.dll -luser32 -lgdi32 -lwinmm -ldxguid
Output file is bin\Debug\sdlz.exe with size 147.95 KB
Running project post-build steps
XCOPY (invalid)\bin\*.dll bin\Debug\ /D /Y
File not found - *.dll
0 File(s) copied
Process terminated with status 4 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
 
I needed to copy sdl2.dll to the projects \bin\debug. Otherwise I get the system error that the program can't run because it can't find sdl2.dll.
 
Done this way, I think the only issue some people may have is if they want to do static linking. I think I've explained thoroughly how I got it to work, but feel free to ask questions.






« Last Edit: November 26, 2022, 03:07:59 pm by lorwerth »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7339
    • My Best Post
Re: Solution for Code::Blocks 20.03 and SDL2 wizard project using mingw
« Reply #1 on: November 29, 2022, 06:18:11 pm »
XCOPY (invalid)\bin\*.dll bin\Debug\ /D /Y

The "(invalid)" implies you set the value of a Global Variable wrong. Look at the pre/post build steps figure out what is wrong and fix it.

Edit: This link covers code tags; please use them.
https://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

Tim S.
« Last Edit: November 29, 2022, 08:08:00 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org