Re: NSBundle question
Re: NSBundle question
- Subject: Re: NSBundle question
- From: Bill Bumgarner <email@hidden>
- Date: Sat, 8 Dec 2001 22:23:17 -0500
I have no idea-- I have never actually dealt w/C++.
I'm not sure if there is an extra link step that has to take place... two
thoughts come to mind: (1) you are going to have to figure out how to
reverse engineer the name mangling (which isn't just for polymorphism, but
is a "feature" of C++ because there are so many compilers out there and no
standards) and (2) you might want to look at using CFBundle as it may have
more awareness of C++ style loading semantics.
Or not.
The suggestion Ondra made-- though snide-- was not bad. If you could wrap
the C++ classes in a simple ObjC or, if you have the lookup stuff working,
a simple functional wrapper, it might make life easier in that you wouldn'
t have to deal w/C++'s symbol mangler.
b.bum
On Saturday, December 8, 2001, at 04:55 PM, R. Eranki wrote:
Thank you! I shall try that out...
Now, when I'm trying to get _C++_ functions using CFBundle, GCC adds the
crap at the end (such as _foo_Fv) (I assume this is for polymorphism)...
I've been using
extern "C" {
// prototypes
}
To remedy this, but it seems kinda hackish. Is there a better way to do
this?
On 12/8/01 1:51 AM, "Bill Bumgarner" <email@hidden> wrote:
( *sigh* People-- *please* stop assuming that the API you prefer --
Carbon,
Cocoa, Java, whatever -- is the *only* way to do things or the *right*
way to do things. In particular, *please* stop assuming that because
someone is doing it some other way, they must be wrong or ignorant... OS
X
is a whole lot bigger than OS 9, OpenStep, or JDK/Swing -- there are lots
of options and people are going to do things in ways you may not agree
with, but are perfectly correct. Sarcasm, arrogance, and responses like
'RTFM: open your eyes, it is damned obvious' don't help anyone. )
For Mach-O files-- I believe NSBundle only loads Mach-O's?-- one can use
the NSModule API to grab a pointer to C functions. See the man page for
NSModule; in particular the various NSLookup* functions. I believe
NSLookupAndBindSymbol() will do what you want once the NSBundle has been
loaded -- you can force loading of the NSBundle by invoking the -load
method, checking the return type to see if it loaded successfully.
Once you find the NSSymbol that you are looking for, NSAddressOfSymbol()
will turn it into an address and you can go from there.
If I remember correctly, gcc effectively prepends an underscore to all
symbols. So, if you need to call the function 'initialize_foo_module' in
the newly loaded bundle, it would look something like:
aSymbol = NSLookupAndBindSymbol("_ initialize_foo_module");
funcPtr = NSAddressOfSymbol(aSymbol);
returnValue = funcPtr(foo, bar, baz);
... or something like that ...
I may have missed a couple of '*'s in that and, certainly, a bit of error
checking would be prudent.
There may be API in the core foundation that covers some of this? I'm
not
sure-- I do know that there is a plug in architecture over in the Carbon
world that may come into play if you are dyna-loading CFM binaries, but
I
don't think it is applicable to mach-o.
b.bum
On Saturday, December 8, 2001, at 01:27 AM, cocoa-dev-
email@hidden.
com wrote:
What if I need to get a specific C function to call? I should use
CFBundle's
functions in this case? I've used NSBundle before invoking ObjC methods,
but
this time I want a set of C functions.
b.bum
I ride tandem with the random....
.... things don't happen the way I planned them.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
ectonot post admin requests to the list. They will be ignored.
b.bum
I ride tandem with the random....
.... things don't happen the way I planned them.