The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Set-up SDL on Mac OSX without Xcode
Karl


Joined: 21 Dec 2016
Posts: 6
Hello. I am interested in learning SDL and intend to follow tutorials / experiment, but regardless of having searched the forums, official instructions, etc. I am having trouble figuring how I am meant to install SDL correctly on a mac *without Xcode*.

I understand that it is probably easier to use Xcode, but I would rather have the opportunity to build a more portable application if I happen to get far enough. Otherwise it might be better to switch to a Linux development environment.

Would anyone know how to install SDL 2 on Mac OSX 10.9 for development outside the Xcode IDE? (The current Xcode installed is 6.2--the latest on the particular system)

So far I have found the following pages:
http://stackoverflow.com/questions/4591076/c-sdl-on-macosx-without-xcode
http://stackoverflow.com/questions/1854444/compiling-sdl-on-os-x-with-makefile

but the discussions describe issues mid-way in the process or with respect to much older operating systems.

This:
http://stackoverflow.com/questions/18585601/compiling-c-sdl-on-macosx?rq=1
in short, indicates that all I need to do is "download the Development Library for OSX and copy it into /Library/Frameworks/." (directly from the dmg? I thought that the dmg has only a package installer. How would I do this?)

and then run something like:
Code:
g++ Main.cpp -o main -I/Library/Frameworks/SDL2.framework/Headers -framework SDL2 -framework Cocoa


That discussion applies to Mac OSX 10.8 though, and a lot might have changed between mountain lion and mavericks. Also, I see that the Cocoa framework is linked in the above example, which suggests that I'd still create a mac-only application.

I am also wondering whether it would be possible to install SDL such that I could use *both* Xcode and makefiles / the command line or any other IDE. Would I run the .dmg to install the libraries in the usual place with the installer?

I am also interested in playing with openGL further in the future. I will be following SDL tutorials from here: http://lazyfoo.net/tutorials/SDL/01_hello_SDL/mac/index.php

Another option is to use an old version of code blocks (13), according to this: (is that a good option?)
https://www.youtube.com/watch?v=Bi9BPEwEMDU
but the tutorial is for a newer version of the OS, and again, I am not sure whether this would work on mavericks. Code::blocks might be the better alternative if it works.

In any case, I would appreciate any help with figuring the best way to proceed with installation and use; much of the documentation and many of the discussions
refer to older OSes, so it would be good to have a confirmation that I am following the correct prodecure in the first place.

Thank you.
Dominus


Joined: 13 Oct 2009
Posts: 127
You NEED Xcode and the command line development tools of xcode installed. After this you can compile and use SDL like you could on linux.
Karl


Joined: 21 Dec 2016
Posts: 6
Right, I understand. Xcode and the developer tools are installed, but I am not sure how to install SDL for use with a different environment. Based on the various discussions of Stackoverflow and the information I have, I don't quite understand what the procedure is.

I know that the binaries are here:

https://www.libsdl.org/download-2.0.php

The basic instructions are here:

https://wiki.libsdl.org/Installation#Mac_OS_X

... which I don't quite understand.

Compiling on Linux would require the following instruction:

Code:
    gcc -o myprogram myprogram.c `sdl2-config --cflags --libs`


But that is unlikely to work immediately on mac.

This command from my post above seems to use the mac-specific cocoa, which is not desirable assuming this will keep the application mac-only:

Code:
g++ Main.cpp -o main -I/Library/Frameworks/SDL2.framework/Headers -framework SDL2 -framework Cocoa


In short I am a little confused by the many ways to install the library and am not sure what I need to do so I can start using the library outside of the IDE provided with Xcode.

Would you (or someone) who might know more about installation on Mac OSX please clarify the instructions? Thanks again.
Dominus


Joined: 13 Oct 2009
Posts: 127
The basic instructions for building on OS X are actually a good start.
Grab the source of SDL (either the last version that comes in an archive or the latest source via mercurial).
Open terminal, cd to the root of the source (unarchived or where you grabbed the source via mercurial), and run the commands from the instructions.
Dominus


Joined: 13 Oct 2009
Posts: 127
Btw, I'd recommend installing a development packager like MacPorts or Homebrew (my recommendation is MacPorts as I'm used to that and they seem tobe more precise than Homebrew but both should work).
And then install SDL via that andyou have development environment for most stuff. Otherwise you are left with the incomplete environment from the Xcode command line tools.
Karl


Joined: 21 Dec 2016
Posts: 6
I have used homebrew to install pre-made formulas, so if there is a way to install SDL via that, then this would be idea.
Is this really all there is to it then, or do I need to follow any other specific instructions afterwards?

http://brewformulas.org/Sdl2

By the way, if this does not work, can I always go back to trying the Xcode-IDE specific way (I don't know if there might be conflicts or left-over files from failed attempts that would cause issues.)

Thanks for your patience. I realize that I am very much a beginner.
Karl


Joined: 21 Dec 2016
Posts: 6
(Apologies for the double post, but I realized that the pre-made homebrew formula is from 2013, so it might not be for the latest version.) How would I combine the Mac OSX instructions for building with the idea of using homebrew for a package manager?
Dominus


Joined: 13 Oct 2009
Posts: 127
I'm sure Honebrew provides instructions on how to completely remove it. I do recommend NOT combining self compiled libs (e.g.SDL2) with either package manager. Not with your current level of experience (don't get me wrong, there are just some pitfalls that you will probably encounter otherwise).
But the instructions would stay the same.

Can't help further with Homebrew, as I wrote, I'm not using it.
Karl


Joined: 21 Dec 2016
Posts: 6
Dominus wrote:
I'm sure Honebrew provides instructions on how to completely remove it. I do recommend NOT combining self compiled libs (e.g.SDL2) with either package manager. Not with your current level of experience (don't get me wrong, there are just some pitfalls that you will probably encounter otherwise).
But the instructions would stay the same.

Can't help further with Homebrew, as I wrote, I'm not using it.


Okay. I don't see anything wrong with having another package manager, so I can go with macports since you know more about it. In this case, how do you go about using macports to install and set-up sdl then? (I already have macports installed and can also go ahead and install X11 if that is necessary. (Is it?))

I found this list:
https://www.macports.org/ports.php?by=name&substr=libsdl

including libsdl2 2.0.5.

Following what I see here: https://guide.macports.org/

Code:
$ port variants libsdl2
libsdl2 has the variants:
   universal: Build for multiple architectures
   x11: Enable X11 support


In that case, would it be best for me to install X11 first and have both variants installed, or should I just pick one or neither?

Code:
$ sudo port install libsdl2 +universal +x11

^ like this?

Should I install any of the other ports listed on the macports page?

Afterwards, what other steps do I need to take before I can write a "hello world" so-to-speak?

Thank you for helping.
Set-up SDL on Mac OSX without Xcode
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
I think you're over-thinking this.

This is the right way to go:
  gcc -o myprogram myprogram.c `sdl2-config --cflags --libs`



It adds -framework Cocoa because that's an SDL dependency, not because you need to write Cocoa code in your application.


You don't need macports, you don't need homebrew. I do all my Mac development using the command line development tools included with Xcode and downloading a few extras like automake and Mercurial.



On Fri, Jan 6, 2017 at 9:18 AM, Karl wrote:
Quote:
Right, I understand. Xcode and the developer tools are installed, but I am not sure how to install SDL for use with a different environment. Based on the various discussions of Stackoverflow and the information I have, I don't quite understand what the procedure is.

I know that the binaries are here:

https://www.libsdl.org/download-2.0.php

The basic instructions are here:

https://wiki.libsdl.org/Installation#Mac_OS_X

... which I don't quite understand.

Compiling on Linux would require the following instruction:




Code:

    gcc -o myprogram myprogram.c `sdl2-config --cflags --libs`




But that is unlikely to work immediately on mac.

This command from my post above seems to use the mac-specific cocoa, which is not desirable assuming this will keep the application mac-only:




Code:

g++ Main.cpp -o main -I/Library/Frameworks/SDL2.framework/Headers -framework SDL2 -framework Cocoa




In short I am a little confused by the many ways to install the library and am not sure what I need to do so I can start using the library outside of the IDE provided with Xcode.

Would you (or someone) who might know more about installation on Mac OSX please clarify the instructions? Thanks again.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Karl


Joined: 21 Dec 2016
Posts: 6
I should have updated the topic--I was able to get SDL working with homebrew, and the basic makefile is set as well.
Without homebrew, would I just download the developer dmg on the site and run the same commad?

In any case, what I have seems to be working.
Set-up SDL on Mac OSX without Xcode
Kai Sterker
Guest

A bit late to reply, but perhaps you will find the information below helpful once you're further into development and looking for a more sophisticated way to build from the command line on OSX (and elsewhere).


Specifically, for macOS what I tend to do is creating a /usr/local directory and then installing all the dependencies like SDL there, by downloading their source packages and compiling them the usual way (I.e. running ./configure, make and make install). While this sometimes proved problematic 5 or 10 years ago, nowadays this normally works out of the box. The benefit of having all that stuff in /usr/local is that (a) it does not interfere with anything that comes with macOS, and (b) once it comes to create an application bundle, I know exactly which libraries to include in the bundle.


When it comes to building my own project, I also use GNU autoconf as a build system, but frankly plain Makefiles or CMake or anything else will work more or less equally well. This part of my build is cross-platform, so the same commands work on Linux, macOS and Windows (using MSys2). But on top of that, I have written a number of shell scripts that contain platform-specific steps of the build, such as the aforementioned App bundle creation on macOS, as well as building a disk image and codesigning for distribution.


Feel free to have a look at the (brief) build instructions, and the macOS-specific scripts:

http://git.savannah.gnu.org/cgit/adonthell.git/tree/README.MacOSX
http://git.savannah.gnu.org/cgit/adonthell.git/tree/make_osx_bundle.sh
http://git.savannah.gnu.org/cgit/adonthell/adonthell-wastesedge.git/tree/make_osx_bundle.sh
http://git.savannah.gnu.org/cgit/adonthell/adonthell-wastesedge.git/tree/osx/make_dmg.sh


Note that in my case there is the added complexity of having to build two projects and merge the outcome to get a working application. Normally a single script would be enough to fully create the App bundle.


Kai






On Sat, Jan 14, 2017 at 10:52 PM, Karl wrote:
Quote:
I should have updated the topic--I was able to get SDL working with homebrew, and the basic makefile is set as well.
Without homebrew, would I just download the developer dmg on the site and run the same commad?

In any case, what I have seems to be working.


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org