www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Derelict SDL2 library not loading on OS X

reply "Joel" <joelcnz gmail.com> writes:
I've installed SDL2.

Joels-MacBook-Pro:DerelictTest joelcnz$ cat test.d

import derelict.sdl2.sdl;

int main() {
	DerelictSDL2.load();
}


Joels-MacBook-Pro:DerelictTest joelcnz$ dmd test 
libDerelictSDL2.a libDerelictUtil.a
Joels-MacBook-Pro:DerelictTest joelcnz$ ./test
derelict.util.exception.SharedLibLoadException source/derelict/u
il/exception.d(35): 
Failed to load one or more shared libraries:
----------------
5   test                                0x0000000108eed3df void 
derelict.util.sharedlib.SharedLib.load(immutable(char)[][]) + 503
6   test                                0x0000000108ee93a0 void 
derelict.util.loader.SharedLibLoader.load(immutable(char)[][]) + 
124
7   test                                0x0000000108ee931c void 
derelict.util.loader.SharedLibLoader.load(immutable(char)[]) + 280
8   test                                0x0000000108ed8508 _Dmain 
+ 40
9   test                                0x0000000108f00098 
D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv + 40
10  test                                0x0000000108efffdd void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) + 45
11  test                                0x0000000108f0003d void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).runAll() + 45
12  test                                0x0000000108efffdd void 
rt.dmain2._d_run_main(int, char**, extern (C) int 
function(char[][])*).tryExec(scope void delegate()) + 45
13  test                                0x0000000108efff59 
_d_run_main + 433
14  test                                0x0000000108ed87d4 main + 
20
15  libdyld.dylib                       0x00007fff8ae8d5c9 start 
+ 1
16  ???                                 0x0000000000000001 0x0 + 1
Dec 17 2014
next sibling parent reply "Jack" <Jackoz530 gmail.com> writes:
On Thursday, 18 December 2014 at 06:29:34 UTC, Joel wrote:
 I've installed SDL2.

 Joels-MacBook-Pro:DerelictTest joelcnz$ cat test.d

 import derelict.sdl2.sdl;

 int main() {
 	DerelictSDL2.load();
 }


 Joels-MacBook-Pro:DerelictTest joelcnz$ dmd test 
 libDerelictSDL2.a libDerelictUtil.a
 Joels-MacBook-Pro:DerelictTest joelcnz$ ./test
 derelict.util.exception.SharedLibLoadException source/derelict/u
il/exception.d(35): 
 Failed to load one or more shared libraries:
 ----------------
 5   test                                0x0000000108eed3df void 
 derelict.util.sharedlib.SharedLib.load(immutable(char)[][]) + 
 503
 6   test                                0x0000000108ee93a0 void 
 derelict.util.loader.SharedLibLoader.load(immutable(char)[][]) 
 + 124
 7   test                                0x0000000108ee931c void 
 derelict.util.loader.SharedLibLoader.load(immutable(char)[]) + 
 280
 8   test                                0x0000000108ed8508 
 _Dmain + 40
 9   test                                0x0000000108f00098 
 D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv + 
 40
 10  test                                0x0000000108efffdd void 
 rt.dmain2._d_run_main(int, char**, extern (C) int 
 function(char[][])*).tryExec(scope void delegate()) + 45
 11  test                                0x0000000108f0003d void 
 rt.dmain2._d_run_main(int, char**, extern (C) int 
 function(char[][])*).runAll() + 45
 12  test                                0x0000000108efffdd void 
 rt.dmain2._d_run_main(int, char**, extern (C) int 
 function(char[][])*).tryExec(scope void delegate()) + 45
 13  test                                0x0000000108efff59 
 _d_run_main + 433
 14  test                                0x0000000108ed87d4 main 
 + 20
 15  libdyld.dylib                       0x00007fff8ae8d5c9 
 start + 1
 16  ???                                 0x0000000000000001 0x0 
 + 1
Did you check if you installed SDL already on your machine?
Dec 17 2014
parent reply "Joel" <joelcnz gmail.com> writes:
 Did you check if you installed SDL already on your machine?
I followed the SDL2 instructions (on the SDL web site) for OS X before using Derelict. It had about copying to a curtain folder, which I did.
Dec 17 2014
parent "Jack" <Jackoz530 gmail.com> writes:
On Thursday, 18 December 2014 at 07:10:43 UTC, Joel wrote:
 Did you check if you installed SDL already on your machine?
I followed the SDL2 instructions (on the SDL web site) for OS X before using Derelict. It had about copying to a curtain folder, which I did.
Just noticed that you used dmd to compile Derelict and dmd's trying to link DerelictUtil (the compiler can't find it). I would suggest for you to get "dub" and build DerelictSDL2 with it. Every package in Derelict needs the Derelict Util package :
libDerelictUtil.a
and when building DerelictSDL2 with dub, it will automatically build the Util package as well. Though take note, I'm not familiar with the other process of building the libraries other than using dub. See
Dub : http://code.dlang.org/download
      http://code.dlang.org/search?q=derelict
      
 https://github.com/DerelictOrg/DerelictUtil/wiki/DerelictUtil-for-Users
Dec 17 2014
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
On 12/18/2014 3:29 PM, Joel wrote:
 I've installed SDL2.

 Joels-MacBook-Pro:DerelictTest joelcnz$ cat test.d

 import derelict.sdl2.sdl;

 int main() {
      DerelictSDL2.load();
 }


 Joels-MacBook-Pro:DerelictTest joelcnz$ dmd test libDerelictSDL2.a
 libDerelictUtil.a
 Joels-MacBook-Pro:DerelictTest joelcnz$ ./test
 derelict.util.exception.SharedLibLoadException source/derelict/util/exception.d(35):
 Failed to load one or more shared libraries:
After that last colon, you should be seeing a list of library names that failed to load. Did you somehow fail to copy/paste it or is it really missing? You can see the names that Derelict searches for by default on Mac at [1]. Make sure that your copy of SDL is installed at one of those locations. Otherwise, you can pass the path to your installed copy to an overload of the load method: DerelictSDL2.load( ["Path/to/your/SDL2/installation.framework/dylib"] ); [1] https://github.com/DerelictOrg/DerelictSDL2/blob/master/source/der lict/sdl2/sdl.d#L42
Dec 18 2014
parent reply "Joel" <joelcnz gmail.com> writes:
[snip]
 Failed to load one or more shared libraries:
After that last colon, you should be seeing a list of library names that failed to load. Did you somehow fail to copy/paste it or is it really missing?
Yes, there was something wrong there, here's another go: Joels-MBP:test joelcnz$ dmd test.d sdl.a util.a Joels-MBP:test joelcnz$ ./test derelict.util.exception.SymbolLoadException derelict/util/exception.d(35): Failed to load symbol SDL_free from shared library /usr/local/lib/libSDL2.dylib ---------------- 5 test 0x00000001046a1993 void derelict.util.loader.SharedLibLoader.bindFunc(void**, immutable(char)[], bool) + 127 6 test 0x000000010469d3dc void derelict.sdl2.sdl.DerelictSDL2Loader.loadSymbols() + 312 7 test 0x00000001046a168f void derelict.util.loader.SharedLibLoader.load(immutable(char)[][]) + 123 8 test 0x00000001046a1611 void derelict.util.loader.SharedLibLoader.load(immutable(char)[]) + 269 9 test 0x00000001046a14fe void derelict.util.loader.SharedLibLoader.load() + 98 10 test 0x000000010469cec5 _Dmain + 21 11 test 0x00000001046b8a64 D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv + 40 12 test 0x00000001046b89a9 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) + 45 13 test 0x00000001046b8a09 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() + 45 14 test 0x00000001046b89a9 void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) + 45 15 test 0x00000001046b8925 _d_run_main + 433 16 test 0x000000010469cee4 main + 20 17 libdyld.dylib 0x00007fff8ac6f5c9 start + 1 18 ??? 0x0000000000000001 0x0 + 1 Joels-MBP:test joelcnz$
 You can see the names that Derelict searches for by default on 
 Mac at [1]. Make sure that your copy of SDL is installed at one 
 of those locations. Otherwise, you can pass the path to your 
 installed copy to an overload of the load method:

 DerelictSDL2.load( 
 ["Path/to/your/SDL2/installation.framework/dylib"] );
I didn't put install with SDL2, libSDL2.dylib was in a different place than were I copied SDL2 (old installation?). And I couldn't get that to work either.
 [1] 
 https://github.com/DerelictOrg/DerelictSDL2/blob/master/source/derelict/sdl2/sdl.d#L42
Dec 18 2014
parent reply Mike Parker <aldacron gmail.com> writes:
On 12/19/2014 9:58 AM, Joel wrote:
 [snip]
 derelict.util.exception.SymbolLoadException derelict/util/exception.d(35):
 Failed to load symbol SDL_free from shared library
 /usr/local/lib/libSDL2.dylib
OK, the loader is finding libSDL2.dylib in /usr/local/lib where it expects it to be. Your error is that it cannot find the SDL_free function in the library. That indicates that the library version of SDL is 2.0.0 (SDL_free was added in 2.0.1) and you are using a branch of Derelict that is implemented against SDL 2.01 or higher. You have three possible solutions here. 1) Use the 2.0.0 branch of Derelict. 2) Uninstall your 2.0.0 installation of SDL and use the latest version (along with the appropriate branch of DerelictSDL2 -- 2.0.1 for SDL 2.0.1 and 2.0.2 for SDL 2.0.2 & 2.0.3 -- you shouldn't be using master). 3) Take advantage of Derelict's selective loading mechanism. This means you can use any branch of Derelict to load older versions of SDL2 by telling Derelict to not to throw exception on certain missing symbols. But that also means that you have to add a complete list of every symbol that was added between SDL 2.0.0 and whichever version corresponds to your version of Derelict. It's only feasible if you don't need the missing functions, but in that case you should go with option 1 anyway. I strongly recommend the first option. Using the 2.0.0 branch allows you to load every version of SDL 2.0.x that has been or will be released. However, if you need certain functions that were added in later versions (such as SDL_GetBasePath which was added in 2.0.1), then you will need to use the 2.0.1 branch of Derelict and require version 2.0.1 at run time.
 I didn't put install with SDL2, libSDL2.dylib was in a different place
 than were I copied SDL2 (old installation?). And I couldn't get that to
 work either.
I'm not quite clear on what you're saying here. Is that you did not copy the version you compiled to /usr/local/lib/libSDL2.dylib and that the version you compiled also failed? At any rate, the options I presented above should help you sort it out. [1] "Selective Symbol Loading" at the bottom of http://derelictorg.github.io/using.html
Dec 18 2014
parent reply "Joel" <joelcnz gmail.com> writes:
Now I get this:

Joels-MacBook-Pro:dere joelcnz$ ./app
derelict.util.exception.SymbolLoadException source/derelict/u
il/exception.d(35): 
Failed to load symbol SDL_GameControllerAddMapping from shared 
library /usr/local/lib/libSDL2.dylib
Dec 19 2014
parent reply Mike Parker <aldacron gmail.com> writes:
On 12/19/2014 7:35 PM, Joel wrote:
 Now I get this:

 Joels-MacBook-Pro:dere joelcnz$ ./app
 derelict.util.exception.SymbolLoadException source/derelict/util/exception.d(35):
 Failed to load symbol SDL_GameControllerAddMapping from shared library
 /usr/local/lib/libSDL2.dylib
OK, it looks like you're actually using a prerelease version of SDL 2. SDL 2.0.0 was released with this function, but several beta versions of SDL 2 were released without it (the game controller mapping API was added a few months before the final 2.0.0 release). Please uninstall this version of SDL from your system and use one of the release versions. For future reference, when you see missing symbol errors like this, it almost always means that you are trying to load an older version of the library. You can solve this by doing exactly what I just did -- looking through the repository history of the library in question. That can help you decide which of the three options I outlined in the previous answer is best. In this case, I used the online mercurial repo browser for SDL 2 [1]. I selected the "release-2.0.0" tag, then clicked "include", then clicked the file link for "SDL_GameController.h". I used Ctrl-f in my web browser to search for SDL_GameControllerAddMapping and found it was there. I then went back to the include directory, clicked "revisions" for the same header and found that the function was added in a commit dated 05 March 2013 [2]. I then looked at the date of the SDL 2.0.0 tag and found it is 11 Aug 2013 [3]. Therefore, if your copy of SDL is missing this file, it is either a prerelease version or it is corrupt, with the former being more likely. [1] https://hg.libsdl.org/SDL [2] https://hg.libsdl.org/SDL/rev/c8aa24f05042 [3] https://hg.libsdl.org/SDL/rev/d6a8fa507a45
Dec 19 2014
parent reply "Joel" <joelcnz gmail.com> writes:
[snip]

 In this case, I used the online mercurial repo browser for SDL 
 2 [1]. I selected the "release-2.0.0" tag, then clicked 
 "include", then clicked the file link for 
 "SDL_GameController.h". I used Ctrl-f in my web browser to 
 search for SDL_GameControllerAddMapping and found it was there. 
 I then went back to the include directory, clicked "revisions" 
 for the same header and found that the function was added in a 
 commit dated 05 March 2013 [2]. I then looked at the date of 
 the SDL 2.0.0 tag and found it is 11 Aug 2013 [3]. Therefore, 
 if your copy of SDL is missing this file, it is either a 
 prerelease version or it is corrupt, with the former being more 
 likely.

 [1] https://hg.libsdl.org/SDL
 [2] https://hg.libsdl.org/SDL/rev/c8aa24f05042
 [3] https://hg.libsdl.org/SDL/rev/d6a8fa507a45
To uninstall SDL, do I just wipe the framework, and SDL dylib?
Dec 19 2014
parent Mike Parker <aldacron gmail.com> writes:
On 12/20/2014 11:46 AM, Joel wrote:

 To uninstall SDL, do I just wipe the framework, and SDL dylib?
Sorry, I can't help you there. I have no idea how things are done on Mac. And I think it depends on how it got there in the first place. You may want to take that question to the SDL mailing list (web interface at [1]) if no one answers here. [1] https://forums.libsdl.org/
Dec 20 2014