• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Executing non objective-c code in a loaded bundle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Executing non objective-c code in a loaded bundle


  • Subject: Re: Executing non objective-c code in a loaded bundle
  • From: Mark Williams <email@hidden>
  • Date: Wed, 28 Jun 2006 09:37:18 -0700

OK, But I don't understand then how to just call the functions.
My code is as follows:

NSBundle * myPlugin = [NSBundle bundleWithPath:@"/path/to/my/ bundle.bundle"];
/*There is no init method in this bundle only c routines.*/


BOOL loaded = bundleLoaded(); //Here in the compiler I would get an undefined symbol error

the bundleLoaded() function is in the bundle I loaded but I don't know how to call it. I tried declaring the functions I needed as extern in the header of the main app but of course since they never are actually defined anywhere in the application I still get the compiler error.


Thanks, Mark.

On Jun 27, 2006, at 10:50 PM, Chris Suter wrote:


On 28/06/2006, at 3:35 PM, Damien Sorresso wrote:

On 27 Jun, 2006, at 11:41 PM, Mark Williams wrote:
I have a bundle with a couple of plain old C functions in it. When I load it I have no trouble executing any objective-c code but I do not know how to execute a regular c function from the loaded bundle like somefunction(); Is it possible to do this or do I have to convert it all to obj-c?


It sounds like you probably have your C functions declared inside

@interface
.
.
.
@end

Move their declarations outside of the `@interface ... @end' context, and you'll be able to call them from `main()' or wherever. You'll also still be able to call them from within the class. Also move the method definitions outside of the `@implementation ... @end' context in your implementation file.

This isn't really the problem.

The problem is getting the symbols linked. If the bundle is loaded by the dynamic linker (as a framework) then this would work fine. However if you're loading it at runtime (which is what I believe is happening here), it's a bit more tricky. It's still possible to have stuff linked later when it's loaded at runtime but you have to link with -flat_namespace and use the -U linker flag (I think).

If you're not worried about duplicate symbols, you don't need to use CFBundle. You can just use dlsym or I think there's an NSModule equivalent. There might be issues with this if running earlier than 10.3 (I'm not sure).

- Chris

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40fornextsoft.com


This email sent to email@hidden



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Executing non objective-c code in a loaded bundle
      • From: Pascal Pochet <email@hidden>
References: 
 >Re: Executing non objective-c code in a loaded bundle (From: Damien Sorresso <email@hidden>)
 >Re: Executing non objective-c code in a loaded bundle (From: Chris Suter <email@hidden>)

  • Prev by Date: Re: Login Item
  • Next by Date: Bind to element in dictionary in array
  • Previous by thread: Re: Executing non objective-c code in a loaded bundle
  • Next by thread: Re: Executing non objective-c code in a loaded bundle
  • Index(es):
    • Date
    • Thread