在OS X上创建和使用静态库 [英] Create and use static library on OS X

查看:130
本文介绍了在OS X上创建和使用静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OK,我试图创建一个Cocoa库(静态)并使用,但我一直收到错误。



我创建了一个超基本的静态库 TSXLib )只有一个额外的类。

  #import ; Foundation / Foundation.h> 

@interface ClassOne:NSObject

- (void)doIt;

@end






  #importClassOne.h

@implementation ClassOne

- (void)doIt
{
NSLog (@哎呀我再次做到了!);
}

@end

strong>动态库安装名称(在Build设置中):

  @executable_path /../ Frameworks / libTSXLib .a 

现在在我的测试项目中:




  • 我拖动了 libTSXLib.a 文件(并将其复制到目标)

  • 添加了一个构建阶段(复制文件),其中我将 libTSXLib.a 复制到 Frameworks
  • 然后我将转到我的 AppDelegate.m 并尝试导入我的图书馆的课

  • #import< ClassOne.h> ,编译器会抛出一个错误,无法找到类






有任何想法吗?






我实际上对图书馆,框架等很困惑(这就是为什么我倾向于尽可能避免它们)。所有我想做的是打包一些类/函数,以便我可以很容易地重新使用它们在不同的项目。无论是框架还是图书馆,我真的不在乎。我需要的是:打包并重新使用我的代码。 (阻止任何人查看/使用内容,捆绑时为加号)的能力


解决方案

好的,所以,一段时间后回来,这是我做的,让它工作:



步骤1:创建库




  • 使用内置的Cocoa库模板创建新项目

  • 设置添加您的课程/功能/任何

  • 构建阶段
  • 在测试项目中


    • 将最终的.a库文件拖放到项目中(didn'

    • 链接到库

    • 更新用户标题搜索路径到您的初始库 .a 文件源(使用递归(如 / the / path / to / your / library / folder / code>)

    • 始终搜索用户路径设置为

    • 构建设置下,将 -ObjC 添加到其他链接器标记


    OK, I'm trying to create a Cocoa Library (static) and use, but I keep getting errors.

    I created a super-basic static Library (TSXLib) with just one additional class in it.

    #import <Foundation/Foundation.h>
    
    @interface ClassOne : NSObject
    
    - (void)doIt;
    
    @end
    


    #import "ClassOne.h"
    
    @implementation ClassOne
    
    - (void)doIt
    {
        NSLog(@"Oops... I did it again!");
    }
    
    @end
    

    Then, I set the Dynamic Library Install Name (in Build Settings) to :

    @executable_path/../Frameworks/libTSXLib.a
    

    Now in my Test Project :

    • I drag'n'drop the libTSXLib.a file (and copied it to target)
    • Added a Build Phase (Copy Files) where I'm copying the libTSXLib.a to Frameworks
    • I'm then going to my AppDelegate.m and try importing my library's class
    • At #import <ClassOne.h>, the compiler throws an error that it can't find the class

    Any ideas?


    NOTE : I'm actually quite confused regarding libraries, frameworks, etc (that's why I tend to avoid them as much as possible). All I'm trying to do is pack some of classes/functions so that I can easily re-use them in different projects. Whether it is a framework, or a library, I really don't care. What I need is that : pack and re-use my code. (the ability to block anyone from seeing/using what's in, when bundled, would be a Plus)

    解决方案

    OK, so, coming back after some time, here's what I did to get it working :

    Step 1 : Create the Library

    • Create a New Project, using the built-in Cocoa Library template
    • Set Library type as Static.
    • Add your Classes/Functions/Whatever
    • Under Build Phases, take care of which headers are going to go Public.

    Step 2 : Use the Library in a test project

    • Drag’n'drop the final .a library file into the project (doesn’t matter if you also copy it to the target directory)
    • Link against the library
    • Update the User Header Search Paths to your initial Library .a file origin (using recursion (like /the/path/to/your/library/folder/**)
    • Set Always search user paths to YES
    • Add -ObjC to Other Linker Flags, under Build Settings.

    这篇关于在OS X上创建和使用静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆