0

I am trying to use SDL with C language sublime text and cygwin

Basically i downloaded the SDL devel mingw32 tar thing and unzipped it

then i copied the includes to cygwin/usr/include as well as the lib from the unzipped file to cygwin lib

also i moved the SDL.dll to the directory where my file written in c is and i included it with #include "SDL.h"

when i tried to compile it i get this error

$ gcc -o sdl sdl.c
sdl.c:1:17: fatal error: SDL.h: No such file or directory
 #include <SDL.h>
                 ^
compilation terminated.

also this is the file i am trying to compile

#include "SDL.h"
#include <stdio.h>

int main(int argc, char *argv[]){

}

can anyone help me out with employing SDL in my programs? i dont know how to make it work and what is missing

yukapuka
  • 87
  • 1
  • 2
  • 8

2 Answers2

1

The #include "SDL.h" line is making the compiler look for a header file called SDL.h. The SDL.dll file you've copied contains the SDL library's compiled code, but only a little bit of the information you need to interface with it. The rest of that information is in the SDL.h header file, which should be in a folder called include in the SDL-devel-*-mingw32.tar archive you downloaded.

You will also have to link your program to the SDL.dll file by adding -lSDL as an argument when you call gcc. I'm not entirely sure if gcc allows you to link directly to a DLL file, so you may also need the libSDL.dll.a file from the lib folder in the archive.

By the way, Sublime Text is just a text editor and should have little to no effect on how your code compiles.

Good luck!

Sine
  • 11
  • 3
  • Here is a related answer about the [difference between a header file and a library](http://stackoverflow.com/a/924495/2938565)! – Sine Jul 06 '14 at 17:39
  • does it matter if the folders which i am copying into are cygwin64 while the download is sdl win32? could that be what is causing the problem? the 64 bit cygwin and the 32 bit SDL clash? because i did copy the files mentioned from the unzipped folders of SDL to the various include spots in cygwin – yukapuka Jul 06 '14 at 19:39
  • It really depends on whether or not cygwin is producing a 64-bit binary. It's likely that it is though, so yes, it will probably clash. If you are adamant that your program must be 64-bit, then you will have to compile a 64-bit version of SDL yourself. (However, I'm not sure if SDL even supports a 64-bit target) – Sine Jul 06 '14 at 19:51
  • i havent really made any specifications in the program that would pertain to it being 64 bit ie using long long(if thats what you mean) all i did was try to compile just a main method and a return with the included "SDL.h" which i have shown above – yukapuka Jul 06 '14 at 19:55
  • so basically as i understand , the compiler is not picking up the include files or library file, is there a way to know if it is because the files are not in the right place, or because of the linker problem? – yukapuka Jul 06 '14 at 19:56
  • The error's description should specify that. SDL is also generally used with its headers in their own directory, so they are included like this: `#include "SDL/SDL.h"`. Are you sure the headers are at the root of cygwin's `include` folder? – Sine Jul 06 '14 at 20:06
0

okay i have found the solution

you need to actually build the file for cygwin by downloading the source file and make & make install

here is the guide

http://www.noquarterarcade.com/using-cygwin-for-sdl-development

yukapuka
  • 87
  • 1
  • 2
  • 8