FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

OSX help
Goto page 1, 2  Next
 
Post new topic   Reply to topic     Forum Index -> Derelict
View previous topic :: View next topic  
Author Message
mwarning



Joined: 01 Apr 2007
Posts: 56

PostPosted: Tue Apr 21, 2009 4:59 pm    Post subject: OSX help Reply with quote

When compiling one of my application using derelict on MacOSX Tiger, I get a runtime error:

Quote:
derelict.util.exception.SharedLibProcLoadException: Failed to load proc objc_registerClassPair from shared library Cocoa.framework/Cocoa


The library is in path /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks
but giving it to the linker doesn't help.

Maybe someone has seen this before and can tell me if I missed some compile options?

A test case would be a Hello World main.d compiled with all derelict libs:
Quote:
dmd main.d derelict/sdl/sdltypes.d derelict/sdl/sdlfuncs.d derelict/sdl/sdl.d derelict/sdl/macinit/SDLMain.d derelict/sdl/macinit/CoreFoundation.d derelict/sdl/macinit/NSAutoreleasePool.d derelict/sdl/macinit/NSMenu.d derelict/sdl/macinit/NSString.d derelict/sdl/macinit/string.d derelict/sdl/macinit/ID.d derelict/sdl/macinit/NSDictionary.d derelict/sdl/macinit/NSMenuItem.d derelict/sdl/macinit/NSZone.d derelict/sdl/macinit/MacTypes.d derelict/sdl/macinit/NSEnumerator.d derelict/sdl/macinit/NSNotification.d derelict/sdl/macinit/runtime.d derelict/sdl/macinit/NSApplication.d derelict/sdl/macinit/NSEvent.d derelict/sdl/macinit/NSObject.d derelict/sdl/macinit/NSArray.d derelict/sdl/macinit/NSGeometry.d derelict/sdl/macinit/NSProcessInfo.d derelict/sdl/macinit/selectors.d derelict/util/wrapper.d derelict/opengl/glfuncs.d derelict/util/exception.d derelict/util/loader.d derelict/util/wintypes.d derelict/opengl/cgl.d derelict/opengl/gl.d derelict/opengl/glu.d derelict/opengl/glx.d derelict/opengl/wgl.d derelict/opengl/gl12.d derelict/opengl/gl13.d derelict/opengl/gl14.d derelict/opengl/gl15.d derelict/opengl/gl20.d derelict/opengl/gl21.d derelict/sdl/mixer.d -L-ldl -ofmain


Ok, it seem to be overkill to include that many derelict files, but I need to use a Makefile.
rebuild would "fix" the runtime error, but it doesn't compile the application in question
because of circular references.
Back to top
View user's profile Send private message
aldacron



Joined: 05 May 2004
Posts: 1322
Location: Seoul, South Korea

PostPosted: Tue Apr 21, 2009 7:21 pm    Post subject: Re: OSX help Reply with quote

mandel wrote:
Ok, it seem to be overkill to include that many derelict files, but I need to use a Makefile.
rebuild would "fix" the runtime error, but it doesn't compile the application in question
because of circular references.


I can't help with the main problem, but what's preventing you from compiling the Derelict libraries and just linking to them?
_________________
The One With D | The One With Aldacron | D Bits
Back to top
View user's profile Send private message Send e-mail
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Wed Apr 22, 2009 2:39 am    Post subject: Re: OSX help Reply with quote

First, SDL in Derelict uses Cocoa, that's a little tricky in D. You first have to create bindings to the Objective-C runtime and then create wrapper classes. The only file that's "need" is derelict/sdl/macinit/SDLMain.d, the other files are bindings to Cocoa, which SDLMain.d needs to work. I only tested it with Mac OS X 10.5 and gdc (dmd wasn't available then).

Ok first it says:
Quote:
derelict.util.exception.SharedLibProcLoadException: Failed to load proc objc_registerClassPair from shared library Cocoa.framework/Cocoa

That should not happen. "objc_registerClassPair" is a key function used in the Objective-C runtime and as far as I know it's critical for anything to work. It's actually located in libobjc.A.dylib but it worked linking only with Cocoa. Perhaps it's different in Mac OS X 10.4 and 10.5.

Quote:
The library is in path /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks
but giving it to the linker doesn't help.

It should be available in /System/Library/Frameworks/ (it is a least on Mac OS X 10.5) it is as critical as the above function. It doesn't help because it's not statically linked, it's linked during runtime. BTW linking a framework (during compile time) using dmd is a little tricky, you have do like this:
Code:
dmd -L-framework -LCocoa
otherwise dmd thinks "Cocoa" is a D file and complaining it can't find "Cocoa.d"

I did, a few days ago, a simple test using Cocoa with D and dmd and it didn't worked. I'll change the code to use libobjc.A.dylib instead and see if it works for you.
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Wed Apr 22, 2009 2:47 am    Post subject: Reply with quote

Ok, I found out what the problem is. I looked at the changes for the Objective-C runtime between Mac OS X 10.5 and 10.4 and saw that these critical functions were added in 10.5:
Code:
objc_allocateClassPair
objc_registerClassPair
class_addMethod

and these were deprecated:
Code:
objc_addClass
class_addMethods

I'll add the deprecated functions and use them when the new functions aren't available.
Back to top
View user's profile Send private message
mwarning



Joined: 01 Apr 2007
Posts: 56

PostPosted: Wed Apr 22, 2009 6:14 am    Post subject: Reply with quote

Hi doob,

thanks for your help!

I tried the Hello World main.d with the long dmd line from above on Leopard
and it worked!

But when I try to load the SDL library
Code:
DerelictSDL.load();


I get:

Code:
derelict.util.exception.SharedLibLoadException: Failed to load one or more shared libraries.
        ../Frameworks/SDL.framework/SDL: dlopen(../Frameworks/SDL.framework/SDL, 2): image not found
        /Library/Frameworks/SDL.framework/SDL: dlopen(/Library/Frameworks/SDL.framework/SDL, 2): image not found
        /System/Library/Frameworks/SDL.framework/SDL: dlopen(/System/Library/Frameworks/SDL.framework/SDL, 2): image not found


I installed the SDL libraries with macports.
Does dlopen expect them to be in a different place?
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Wed Apr 22, 2009 12:59 pm    Post subject: Reply with quote

As the error message says the SDL framework is expected to be in one of the following paths:
Code:
../Frameworks/SDL.framework
/Library/Frameworks/SDL.framework
/System/Library/Frameworks/SDL.framework

The above paths are where derelict searches for SDL (you can supply your own search path to the load function). When you install something with macport it installs it in /opt as default, I'm not sure if the installation creates any symlinks. Usually macport builds and installs dylibs and not frameworks. BTW you said something about circular references, what was that?
Back to top
View user's profile Send private message
mwarning



Joined: 01 Apr 2007
Posts: 56

PostPosted: Thu Apr 23, 2009 10:07 pm    Post subject: Reply with quote

I will try to make those folders link to the sdl libs for now.

Quote:

BTW you said something about circular references, what was that?


The circular references are in the application I try to compile.
It's a bit annoying because the link order is important for that to work.
It's not my code. Wink
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Fri Apr 24, 2009 3:05 am    Post subject: Reply with quote

Do you have a test case? Last I checked with a simple SDL sample code there were no circular references.
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Fri Apr 24, 2009 12:52 pm    Post subject: Reply with quote

I just updated my derelict to latest trunk and tested this code: http://tango.pastebin.com/m122079c8 both with gdc and dmd, both worked. Mac OS X 10.5.6
Back to top
View user's profile Send private message
mwarning



Joined: 01 Apr 2007
Posts: 56

PostPosted: Fri Apr 24, 2009 6:08 pm    Post subject: Reply with quote

Code:
Do you have a test case?


It has nothing to do with derelict. Smile


Quote:
I just updated my derelict to latest trunk and tested this code [...]


I will give it a try.
Back to top
View user's profile Send private message
mwarning



Joined: 01 Apr 2007
Posts: 56

PostPosted: Sat Apr 25, 2009 6:16 am    Post subject: Reply with quote

Your test case works for me.
But it fails when I also try to load SDLMixer .


Quote:
derelict.util.exception.SharedLibLoadException: Failed to load one or more shared libraries.
../Frameworks/SDL.framework/SDL: dlopen(../Frameworks/SDL.framework/SDL, 2): image not found
/Library/Frameworks/SDL.framework/SDL: dlopen(/Library/Frameworks/SDL.framework/SDL, 2): image not found
/System/Library/Frameworks/SDL.framework/SDL: dlopen(/System/Library/Frameworks/SDL.framework/SDL, 2): image not found
Back to top
View user's profile Send private message
mwarning



Joined: 01 Apr 2007
Posts: 56

PostPosted: Sat Apr 25, 2009 9:46 am    Post subject: Reply with quote

Problem solved.

I installed sdl mixer along with the sdl framework
After installing this, it worked.
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Sun Apr 26, 2009 5:11 am    Post subject: Reply with quote

Good to hear.
Back to top
View user's profile Send private message
mwarning



Joined: 01 Apr 2007
Posts: 56

PostPosted: Tue Apr 28, 2009 1:37 pm    Post subject: Reply with quote

Any idea when you will add the deprecated functions?
Being able to run programs on Tiger as well would be great.

There probably is a nice way to distinguish between Tiger and Leopard.
I had a quick look but only found compile time constants so far..
Back to top
View user's profile Send private message
doob



Joined: 06 Jan 2007
Posts: 367

PostPosted: Wed Apr 29, 2009 2:39 am    Post subject: Reply with quote

mandel wrote:
Any idea when you will add the deprecated functions?
Being able to run programs on Tiger as well would be great.

I'll add them some day this week.

mandel wrote:
There probably is a nice way to distinguish between Tiger and Leopard.
I had a quick look but only found compile time constants so far..

I haven't seen any nice way to do it. There is a function in Carbon called Gestalt but I wouldn't consider it a nice way. I thought that I would just try to load the 10.5 functions and if they fail fall back to the deprecated functions.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Derelict All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group