Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: DSFML + Mac OS X  (Read 12708 times)

0 Members and 1 Guest are viewing this topic.

MattUK

  • Newbie
  • *
  • Posts: 5
    • View Profile
DSFML + Mac OS X
« on: July 18, 2013, 08:47:05 pm »
Hi!

I recently came across Jebbs' DSFML binding, I've been looking for an Object-Oriented wrapper, and Derelict is limited by the fact it uses a C binding (aka no OO).

However, the libraries included are all either .dll or .lib, neither of which are supported by dmd on OS X. Does anyone have a guide on how to build DSFML for OS X, and produce .o or .a files (the library types supported by dmd for Mac).

Thanks,
Matt.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: DSFML + Mac OS X
« Reply #1 on: July 19, 2013, 08:34:52 pm »
However, the libraries included are all either .dll or .lib, neither of which are supported by dmd on OS X.

That is completely my own fault. DSFML was in the works before SFML 2.0 was officially released, and since I develop mainly on Windows I provided .dll's and .lib's for the most up to date version of CSFML for convenience to those that wanted to test it(Since DSFML currently runs by linking with CSFML).

It looks like the official downloads for CSFML for OSX don't provide .a files, only the .dylib's. Does OSX provide some kind of import library generator so that you can create the .a files from pre-existing .dylib's? Or perhaps DMD is able to link directly to .dylib's? If not, then you will have to build from scratch and probably make .a/.so's.

I've been meaning to write a wiki for the steps required to build CSFML anyways, so let me know if you need that in order to get DSFML up and running, but hopefully you can just download CSFML from here and just link with the .dylib's.


I don't have a Mac, and I believe that everyone that's worked on DSFML with me on GitHub uses either Windows or Linux, so this would be a great opportunity to make sure DSFML works on OSX as well. :)

P.S.
I just made a post on the D forums to see if there's any way for DMD to link directly to .dylib files.
DSFML - SFML for the D Programming Language.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: DSFML + Mac OS X
« Reply #2 on: July 19, 2013, 08:44:01 pm »
.a files are for static libraries, .dylib (like .so on Linux) are for dynamic libraries. I know nothing about D so I can't help much but generally speaking, can't you use dynamic libs? I highly recommend to use those if possible. However, if you can't use them, compiling SFML (and it's the same for CSFML) as static libs you need to set BUILD_SHARED_LIBS to false when generating Makefile with CMake. (As usual, all the details are in the officiel tutorial here.)
SFML / OS X developer

MattUK

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: DSFML + Mac OS X
« Reply #3 on: July 19, 2013, 09:20:55 pm »
Thanks for the replies guys! It turns out that you can actually link to .dylibs with D (although the website page on the OS X compiler makes no mention of this ability).

I googled for "dmd dylib" and it turns out that using the compiler switch "-L<path to lib>/libname.dylib" will link the binaries in!

So, to compile a test program with DMD on OS X, you must do the following (assuming you installed CSFML into the directory recommended by the install instructions):

Code: [Select]
dmd main.d system.d audio.d graphics.d window.d network.d -L/usr/local/lib/libcsfml-system.dylib -L/usr/local/lib/libcsfml-audio.dylib -L/usr/local/lib/libcsfml-graphics.dylib -L/usr/local/lib/libcsfml-network.dylib -L/usr/local/lib/libcsfml-window.dylib
It seems you cannot just link in the entire directory, and each *.dylib must be included by name.

I've yet to fully test whether it works or not, but I suspect there are no issues (if it works on Linux, one could presume it should work on OS X).

Edit: Just tested, and yep, works perfectly! Thanks for the bindings, Jebbs :P
« Last Edit: July 19, 2013, 09:44:30 pm by MattUK »

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: DSFML + Mac OS X
« Reply #4 on: July 19, 2013, 09:51:32 pm »
.a files are for static libraries, .dylib (like .so on Linux) are for dynamic libraries.

That very well could be my ignorance of being mainly a Windows dev showing. :P  Windows has "import  libraries" that you link against instead of linking with the shared library itself.

Thanks for the replies guys! It turns out that you can actually link to .dylibs with D (although the website page on the OS X compiler makes no mention of this ability).

I googled for "dmd dylib" and it turns out that using the compiler switch "-L<path to lib>/libname.dylib" will link the binaries in!

It seems you cannot just link in the entire directory, and each *.dylib must be included by name.

I'm working on a revised system that makes the build/link process easier(and makes way more sense) for DSFML, so this is very good to know.

Is it possible to add a search directory to the linker and then use just the names of the dylib's? Something like

Code: [Select]
dmd main.d system.d audio.d graphics.d window.d network.d -L+/usr/local/lib/ -Llibcsfml-system.dylib -Llibcsfml-audio.dylib -Llibcsfml-graphics.dylib -Llibcsfml-network.dylib -Llibcsfml-window.dylib

Quote
Thanks for the bindings, Jebb :P

You're welcome!

Edit: Fixed a sentence that made no sense. :P
« Last Edit: July 19, 2013, 09:58:42 pm by Jebbs »
DSFML - SFML for the D Programming Language.

MattUK

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: DSFML + Mac OS X
« Reply #5 on: July 19, 2013, 10:56:02 pm »
Is it possible to add a search directory to the linker and then use just the names of the dylib's? Something like

Code: [Select]
dmd main.d system.d audio.d graphics.d window.d network.d -L+/usr/local/lib/ -Llibcsfml-system.dylib -Llibcsfml-audio.dylib -Llibcsfml-graphics.dylib -Llibcsfml-network.dylib -Llibcsfml-window.dylib

Purely copy-pasting that results in the linker telling me that no such directory ("+/usr/local/lib") exists. Changing it to "-L/usr/local/lib" has the linker telling me no such file ("libcsfml-system.dylib") exists.

Sadly, I don't think there is a way around having to include all these parameters.

I'm currently using Mono-D, so I've attached a guide (in PDF form) to help those on OS X (mainly), but it could probably be used by those on Linux/Windows, too.

(Can't attach it on the forum, so I've uploaded it to MediaFire: http://www.mediafire.com/view/71feojna1n25fiy/Setting_up_DSFML_with_Mono.pdf)

Regards,
Matt.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: DSFML + Mac OS X
« Reply #6 on: July 19, 2013, 11:34:32 pm »
-L+, as it turns out is Windows specific(to Optlink), and after looking around I think I got it.

Instead, try:
-L-L/usr/local/lib/

The first -L passes the "-L/usr/local/lib/" to the linker, which should keep /usr/local/lib/ as a path to look for your dylib's. Hopefully that one works. I would be *very* surprised if there was no way to give the linker a search directory.

Quote
I'm currently using Mono-D
I currently use Mono-D too, though I've been considering the idea of writing a new IDE in D using GtkD. :P
DSFML - SFML for the D Programming Language.

MattUK

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: DSFML + Mac OS X
« Reply #7 on: July 19, 2013, 11:47:40 pm »
-L+, as it turns out is Windows specific(to Optlink), and after looking around I think I got it.

Instead, try:
-L-L/usr/local/lib/

The first -L passes the "-L/usr/local/lib/" to the linker, which should keep /usr/local/lib/ as a path to look for your dylib's. Hopefully that one works. I would be *very* surprised if there was no way to give the linker a search directory.

Quote
I'm currently using Mono-D
I currently use Mono-D too, though I've been considering the idea of writing a new IDE in D using GtkD. :P

I did actually try changing it to -L-L, but the linker still reports that "libcsfml-system.dylib could not be found." Very odd...

And an IDE would be a cool project! I had a look into making a plugin for IntelliJ, but I had no idea where to start, haha.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: DSFML + Mac OS X
« Reply #8 on: July 20, 2013, 12:10:44 am »
Very odd indeed.

Well, in order to get my new build system to work, I have to figure a way to make certain I have this stuff working. If I ever figure it out, I'll let you know.

Quote
And an IDE would be a cool project! I had a look into making a plugin for IntelliJ, but I had no idea where to start, haha.

I thought so too! It would be super fun to work on and D deserves something nice like a modern cross platform IDE that isn't a plug in for a different editor. I have too much on my plate already though, so I won't be starting on it for a while yet. :P
DSFML - SFML for the D Programming Language.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: DSFML + Mac OS X
« Reply #9 on: July 20, 2013, 08:13:29 am »
Regarding the compilation, gcc, clang and most C compiler have two options: -llib and -Ldir. (lower and upper case el). You would typically use
gcc ... -L/usr/local/lib -lsfml-window ...

Doesn't dmd have those options too?
SFML / OS X developer

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: DSFML + Mac OS X
« Reply #10 on: July 20, 2013, 08:34:31 am »
It does, but DMD is actually a front end of the compiler. It uses different back ends for different systems. You actually came up with the answer I was looking for as DMD uses gcc for linkage on OSX.

When using DMD it has its own -L switch in order for it to know what to pass to the linker. So I guess it is actually going to be:
Code: [Select]
dmd main.d system.d audio.d graphics.d window.d network.d -L-L/usr/local/lib/ -L-lcsfml-system -L-lcsfml-audio -L-lcsfml-graphics -L-lcsfml-network -L-lcsfml-window
And if that works it means the idea I had will work perfectly!
DSFML - SFML for the D Programming Language.

MattUK

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: DSFML + Mac OS X
« Reply #11 on: July 20, 2013, 11:18:32 am »
It does, but DMD is actually a front end of the compiler. It uses different back ends for different systems. You actually came up with the answer I was looking for as DMD uses gcc for linkage on OSX.

When using DMD it has its own -L switch in order for it to know what to pass to the linker. So I guess it is actually going to be:
Code: [Select]
dmd main.d system.d audio.d graphics.d window.d network.d -L-L/usr/local/lib/ -L-lcsfml-system -L-lcsfml-audio -L-lcsfml-graphics -L-lcsfml-network -L-lcsfml-window
And if that works it means the idea I had will work perfectly!

Just tried it now, and the compilation was successful!

Matt.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: DSFML + Mac OS X
« Reply #12 on: July 25, 2013, 05:54:52 am »
I'm going to try to get the new build system done and a few more tutorials written before the start of the SFML Game Jam, so I had a little question for you:

Do you have any problems building/running DSFML as a 64bit program? Linux has this issue and I wanted to confirm what was going on for OSX, but I currently have to way to test. :P
DSFML - SFML for the D Programming Language.