Re: Loading the Foundation at runtime
Re: Loading the Foundation at runtime
- Subject: Re: Loading the Foundation at runtime
- From: Eric Wing <email@hidden>
- Date: Wed, 26 Jan 2011 17:36:41 -0800
On 1/24/11, Mathieu Suen <email@hidden> wrote:
> Hi All,
>
> In other to write a binding for a language I need to load the Foundation
> framework at run time.
> So just to test I wrote a simple example:
>
> ----------objc-test.c----------
> #include <objc/runtime.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> void
> onLoad (Class this, char* inCat)
> {
> printf ("Loading %s in %s\n", class_getName (this), inCat);
> }
>
>
>
> int
> main ()
> {
> int error;
> objc_loadModule ("Foundation", onLoad, &error);
> return EXIT_SUCCESS;
> }
> ----------objc-test.c----------
>
> But the linker complain:
>
> Undefined symbols:
> "_objc_loadModule", referenced from:
> _main in ccX2yu3T.o
> ld: symbol(s) not found
>
> I have compile it using the command:
> gcc objc-test.c -g -lobjc -o test
>
I think you should be using dlopen() instead, e.g.
dlopen("/System/Library/Frameworks/Foundation.framework/Versions/Current/Foundation",
RTLD_LAZY);
dlopen() is what I use in LuaCocoa and it works in 10.5 and 10.6 and
32-bit and 64-bit and PowerPC and Intel. I'm pretty sure that's what
all the other language bridges use too.
-Eric
--
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden