views:

60

answers:

1

I'm attempting to write my first custom Cocoa Framework and I want to expose a simple C function from the framework that wraps up a bunch of functionality, much like NSApplicationMain does. When I simply imported the files directly from within the project, everything went fine, the project built and my C function was called correctly.

Now I have a new Cocoa Framework project which contains the files, I cant build my program because I get "Symbols not found" error messages, specifically for my C function.

I've tried prefixing the function definition in the header file with extern, but still nothing.

Can anyone give me a heads up? How can I expose standard C functions via custom Cocoa Framework?

Rough idea of what I'm doing:

My Program that uses my custom framework:

#import <BDWebApplicationFramework/BDWebApplication.h>

int main (int argc, const char * argv[]) {
    return BDWebApplicationMain(argc, (const char **)argv);
}

My framework header: BDWebApplication.h

#import <Foundation/Foundation.h>

@interface BDWebApplication : NSObject {
    NSString *name;
}
@property (readwrite, copy) NSString *name;

@end

extern int BDWebApplicationMain(int argc, const char * argv[]);

My framework file: BDWebApplication.m

#import "BDWebApplication.h"

@implementation BDWebApplication

@synthesize name;

- (id)init
{
    [super init];
    name = @"New name";
    return self;
}

- (void)dealloc
{
    [name release];
    [super dealloc];
}

@end

int BDWebApplicationMain(int argc, const char * argv[])
{
   // Do some Obj-c stuff here
}
+2  A: 

The problem here is almost certainly buried within your Xcode build settings, not in the code you've posted (which looks fine).

First things first: Are you linking to your new framework? Assuming you are, are you sure you're actually exporting the symbols you think you are when you build the framework? (There are a number of options for specifying this, and some of them have semantics than can surprise the unwary.)

What would be more useful in helping you diagnose this is the full text of the Xcode build transcripts for both the framework and the executable.

Kaelin Colclasure
I originally followed the instructions found here: http://atastypixel.com/blog/creating-applications-in-xcode-using-frameworks/to create a framework project inside my program project, which should also create a framework that is available to any other of my projects. The sourcecode for my project is available here, tar'ed and gziped, for you to examine. Its just shy of a 7Mb download:http://restafarian.com/stackoverflow/stackoverflow.tgzThanks for any help and advice you can provide!
omarshariffdontlikeit
The problem is indeed that your BDWebAppTest target is not being linked against your BDWebApplicationFramework framework (sic). To see that, disclose the full tree of dependencies under the target's outline and note particularly the "Link Binary With Libraries" step. You'll see that right now it's only linking against Foundation.framework. You can fix that problem by drag-and-dropping your framework into the list of linked frameworks. (And probably RegexKit too, since I assume your project is referencing it for a reason.)
Kaelin Colclasure
Excellent stuff, that worked as described. As far as I am aware, I shouldn't need to link RegexKit with my program, as that should be linked with my framework, as it is only my framework that will be using RegexKit behind the scenes.Thanks for your help, I know I must have missed something. I have posted a comment on the original blog whose instructions I followed and asked him to add this step to his instructions. Hopefully that will help anyone else who has a similar problem.
omarshariffdontlikeit
Just a quick note: I will leave my sample project up at the address above for a couple of months just in case anyone else has a similar problem and would like to follow these instructions to see how Kaelin's advice fixes the issue.
omarshariffdontlikeit