News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Cannot get SDL to work in MinGW

Started by JonMW, December 02, 2008, 12:35:55 PM

Previous topic - Next topic

JonMW

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: wikiStep 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: wikiStep 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?

TDragon

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>.
[url="https://jmeubank.github.io/tdm-gcc/"]https://jmeubank.github.io/tdm-gcc/[/url] - TDM-GCC compiler suite for Windows (GCC 9.2.0 2020-03-08, 32/64-bit, no extra DLLs)

MortenMacFly

Quote from: TDragon 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.
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

JonMW

Quote from: TDragon 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>.
It worked! Incredible... I was so sure that I'd made some error somewhere.
Thanks to both of you!

stahta01

#4
Quote from: MortenMacFly on December 02, 2008, 08:49:34 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".


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);
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]