Cocoa应用程序无法找到dylib头文件

时间:2012-04-24 15:19:24

标签: xcode macos cocoa dylib

我从xcode创建了一个cocoa dylib模板,并根据苹果文档

添加了头文件

Person.h具有以下代码

#import <Cocoa/Cocoa.h>

@protocol Person

- (void)setName:(NSString*)name;

- (NSString*)name;

@end

@interface Person : NSObject <Person>{

@private

    NSString* _person_name;

}

和Titling.h具有以下代码

#import <Cocoa/Cocoa.h>

#import "Person.h"



@protocol Titling

- (void)setTitle:(NSString*)title;

@end

@interface Person (Titling) <Titling> {

}

@end

这就是我在dylib中编译的所有代码,并且没有错误构建成功。

在此之后我创建了一个新的cocoa应用程序,将dylib(cocoaLibrary.dylib)拖到资源文件夹cocoa application.added applicationatiodidFinishLaunching中的代码

#import "loadCocoaLibAppDelegate.h"

#import <dlfcn.h>

#import "Person.h"

#import "Titling.h"

@implementation loadCocoaLibAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application 


    //NSAutoreleasePool* pool = [NSAutoreleasePool new];



    // Open the Person library.

    void* lib_handle = dlopen("./libPerson.dylib", RTLD_LOCAL);

    if (!lib_handle) {

        exit(EXIT_FAILURE);

    }



    // Get the Person class (required with runtime loaded libraries).

    Class Person_class = objc_getClass("Person");

    if (!Person_class) {

        exit(EXIT_FAILURE);

    }



    // Create an instance of Person.

    NSObject<Person,Titling>* person = [Person_class new];



    // Use person.

    [person setName:@"Perrine LeVan"];

    NSLog(@"[%s] main: [person name] = %@", __FILE__, [person name]);

    [person setTitle:@"Ms."];

    NSLog(@"[%s] main: [person name] = %@", __FILE__, [person name]);



    // Dispose of person.

    [person release];



    // Close the Person library.

    if (dlclose(lib_handle) != 0) {

        exit(EXIT_FAILURE);

    }



   // [pool release];

}

@end

Person.h:没有这样的文件或目录

Titling.h:没有这样的文件或目录

我真的不知道如何解决这个问题。请帮助。

0 个答案:

没有答案