Exposing C function from custom Objective-C Framework
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
}
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.
精彩评论