Author Topic: Cannot get SDL to work in MinGW  (Read 5584 times)

JonMW

  • Guest
Cannot get SDL to work in MinGW
« on: December 02, 2008, 12:35:55 pm »
When I began dabbling in C, I would write directly with notepad and compile with DJGPP - this worked well enough for the extremely small programs that I wrote at home for my own amusement. Eventually, I worked out that for a graphical interaction with the use, I would use SDL. I discovered that DJGPP was not compatible with SDL, and hence I moved to MinGW.
After reading a few pages of a C SDL tutorial, I decided that notepad wasn't going to be the most efficient way forward - I went with the suggested program, Code::Blocks.

This is where the problems began. Even after several uninstalls/reinstalls and following step-by-step instructions, I am apparently not doing it right.

This is my latest attempt:
I'm running Windows XP.
First, I uninstalled all of the previously mentioned programs and deleted any remaining folders/files.
I downloaded codeblocks-8.02mingw-setup.exe, and installed it. I ticked the box so that it would automatically install MinGW, detect it, and set it as default.

I downloaded SDL-devel-1.2.13-mingw32.tar.gz and extracted the archive into its own folder elsewhere on my system.

Then I followed the instructions given here following "the good" instructions and then continuing down through "The Process".

I'll be verbose - for each step given, I'll say exactly what I did...
(Steps 1 and 2 are already covered with sufficient detail)
Quote from: wiki
Step 3: Copy SDL.dll from inside the bin folder to the your compilers bin directory (ie C:\Mingw\bin) This allows the compiler to find the dll at runtime time without having to put it in the same folder as your program or in the windows folder.
I copied sdl.dll into C:\Program Files\CodeBlocks\MinGW\bin

Quote from: wiki
Step 4: Copy the contents of lib to your compiler's lib folder. If MinGW is installed under C:\MinGW, then this will be C:\MinGW\lib.
Much like step 2, I copied the contents of the lib file in my SDL archive (three files - two .a's and one .la) into C:\Program Files\CodeBlocks\MinGW\lib

Step 5... it goes on like this.

I decided to perform the optional Step 6 - placing SDL.dll into C:\Windows

I have not yet tried to follow the "Alternative" method (listed under "the good").

Here's a screenshot of the final file structure (relevant, I hope)


That covers "The Good", and I move onto the bottom section, "The Process".
Following the given instructions, I start a new project with the SDL template.
It then asks me to provide the location of SDL on my computer - this doesn't seem to be mentioned in the guide at all. However, the window states 'this folder must contain the subfolders "include" and "lib" ' So I went with C:\Program Files\CodeBlocks\MinGW - it meets the stated requirements and I believe I had copied the necessary files into its subfolders.
Then the error message pops up:


Now, I've seen no mention of this header file up until now, so I'm totally stumped.
I'm doing it wrong - but how do I fix it?

Offline TDragon

  • Lives here!
  • ****
  • Posts: 943
    • TDM-GCC
Re: Cannot get SDL to work in MinGW
« Reply #1 on: December 02, 2008, 05:32:07 pm »
Unfortunately, the Code::Blocks SDL wizard hasn't been updated since SDL changed its include file layout. Not your fault. To get by this, temporarily copy SDL.h up a level (from "SDL" to "include"). This is just to get the wizard to finish; you should then get rid of the copy and adjust any #include <SDL.h> to #include <SDL/SDL.h>.
https://jmeubank.github.io/tdm-gcc/ - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Cannot get SDL to work in MinGW
« Reply #2 on: December 02, 2008, 08:49:34 pm »
Unfortunately, the Code::Blocks SDL wizard hasn't been updated since SDL changed its include file layout.
Alternatively easily modify the wizard accordingly (and, if you like, provide us with a patch). To do so directly from the page where you choose the wizards: Right-Click on the SDL wizard and select "Edit" (or was it "Modify"... I don't remember exactly). This wizard is very tiny - you will easily find the position where the include path is defined.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

JonMW

  • Guest
Re: Cannot get SDL to work in MinGW
« Reply #3 on: December 03, 2008, 04:05:02 am »
Unfortunately, the Code::Blocks SDL wizard hasn't been updated since SDL changed its include file layout. Not your fault. To get by this, temporarily copy SDL.h up a level (from "SDL" to "include"). This is just to get the wizard to finish; you should then get rid of the copy and adjust any #include <SDL.h> to #include <SDL/SDL.h>.
It worked! Incredible... I was so sure that I'd made some error somewhere.
Thanks to both of you!

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Cannot get SDL to work in MinGW
« Reply #4 on: December 03, 2008, 01:07:28 pm »
Alternatively easily modify the wizard accordingly (and, if you like, provide us with a patch). To do so directly from the page where you choose the wizards: Right-Click on the SDL wizard and select "Edit" (or was it "Modify"... I don't remember exactly). This wizard is very tiny - you will easily find the position where the include path is defined.

Tested Patch using MinGW GCC; With the changes I think MSVC needs, it finally worked OK.

Should be tested on an Linux Machine.
Should be tested Using MSVC.

FYI: The VC8 dev file did NOT use the include "SDL/SDL.h" used just "SDL.h".

Code
Index: src/plugins/scriptedwizard/resources/sdl/files/main.cpp
===================================================================
--- src/plugins/scriptedwizard/resources/sdl/files/main.cpp (revision 5327)
+++ src/plugins/scriptedwizard/resources/sdl/files/main.cpp (working copy)
@@ -3,10 +3,10 @@
 #else
     #include <stdlib.h>
 #endif
-#ifdef __APPLE__
-#include <SDL/SDL.h>
+#ifdef _MSC_VER
+    #include <SDL.h>
 #else
-#include <SDL.h>
+    #include <SDL/SDL.h>
 #endif
 
 int main ( int argc, char** argv )
Index: src/plugins/scriptedwizard/resources/sdl/wizard.script
===================================================================
--- src/plugins/scriptedwizard/resources/sdl/wizard.script (revision 5327)
+++ src/plugins/scriptedwizard/resources/sdl/wizard.script (working copy)
@@ -47,8 +47,12 @@
         local dir_nomacro_inc = GetCompilerIncludeDir(dir, SDLPathDefault, SDLPathDefaultInc);
         if (dir_nomacro_inc.IsEmpty())
             return false;
-        if (!VerifyFile(dir_nomacro_inc, _T("SDL.h"), _T("SDL's include")))
+
+        local is_msvc = GetCompilerFactory().CompilerInheritsFrom(Wizard.GetCompilerID(), _T("msvc*"));
+        if (is_msvc && !VerifyFile(dir_nomacro_inc, _T("SDL.h"), _T("SDL's include")))
             return false;
+        if (!is_msvc && !VerifyFile(dir_nomacro_inc, _T("SDL/SDL.h"), _T("SDL's include")))
+            return false;
 
         // verify library dependencies
         local dir_nomacro_lib = GetCompilerLibDir(dir, SDLPathDefault, SDLPathDefaultLib);
« Last Edit: December 03, 2008, 01:27:25 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org