Hi all! I’ve read a lot around online, but I’m still having trouble with something that most people probably know how to do…please help!
I want to build a cross platform game with SDL 2, but I don’t want to use Xcode / Visual Studio / etc. (and I want to avoid using the Frameworks stuff if possible) Just a plain 'ol compiler and text editor! However, I can’t even compile my game (right now just trying to open a window). The compiler can’t find the necessary SDL files. So, here’s what I’m doing:
Then I follow the instructions for Mac OS X here: http://wiki.libsdl.org/Installation#Mac_OS_X
a) I switch to the directory with the files, and make a folder named ‘build’
b) I ‘cd’ into the build folder, and run ‘CC=/where/i/cloned/SDL/build-scripts/gcc-fat.sh …/configure ; make’
It gives me this message: make: *** No targets specified and no makefile found. Stop.
c) If I drop the CC part, and just run ‘…/configure; make’, it seems to build correctly?
Here comes the tricky part. SDL seems to have built correctly… so how do I build the game? My file is in the build folder, where sdl2-config is. I try running things like: [ clang -o myGame game.c ‘sdl2-config --cflags --libs’ ] but I get this error: [ clang: error: no such file or directory: ‘sdl2-config --cflags --libs’ ]
When I just doing: [ clang -o myGame game.c ], I get this: [ fatal error: ‘SDL.h’ file not found ]
Thank you for reading, and thanks for the help. I really appreciate it!
Apparently sdl2-config can’t be found because it’s not in $PATH, which might be expected when using Frameworks (not sure, I’m not a Mac user)?
But I guess when using a Framework one shouldn’t need sdl2-config, but “just” tell the compiler what framework to link against (and maybe where it can be found if it’s not in a standard path). At least that’s my understanding of how they’re supposed to work…
OTOH, maybe the problem is using the wrong kind of quotes around the sdl2-config command: it should be backticks (`), not single quotes (’)… unfortunately, discourse fucks up the formatting of those, even in code-blocks blocks (at least in preview)…
Ye I did notice that but I was hoping he would copy and paste my example exactly.
He should be able to run sdl2-config --cflags --libs in the terminal to find the path of the header and lib.
The path should be automagically configured if you use brew install.
Just out of curiosity, I’ll uninstall sdl installed with brew, and see if this method works using what I have in the /build folder.
Oh… and @Daniel_Gibson, I guess to answer some of your previous comments… I wanted to avoid using Frameworks & Xcode. Thank you for posting the lazy foo tutorials, they are very helpful.
You can use frameworks from commandline as well, I think -F/path/to/directory lets you set a directory to look for them and -framework SDL2 tells clang to use it.
BTW, if backticks are not working in fish, in bash an alternative form is $(sdl2-config bla), maybe there is something similar in fish? I think “Command substitution” is the term you should be looking for
Thanks! I’ll try that code, and look into what’s going on with fish.
So… when attempting to compile without homebrew, it still doesn’t work. What is homebrew doing that I’m doing incorrectly? I downloaded the libs, built them, and added the /build folder (where the build for SDL is) to my path. I’ve tried executing the clang command for my file on the desktop, and within the build folder, and I’m still getting the error: ‘SDL.h’ file not found?
sdl2-config is a tool that is used to configure and determine the compiler and linker flags that should be used to compile and link programs, libraries, and plugins that use
SDL. It is also used internally by the m4 macros that are included with SDL.