静态库

作者: 卟过尔尔 | 来源:发表于2021-01-26 16:40 被阅读0次

TestExample.h
TestExample.m

TestExample.m —> TestExample.o

clang -x objective-c \
-target x86_64-apple-macos11.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk \
-c TestExample.m -o TestExample.o

命令:
-x: 指定编译文件语言类型,使用OC
-target:指定架构,Big Sur是:x86_64-apple-macos11.1,之前是:x86_64-apple-macos10.15
-fobjc-arc:使用ARC
-isysroot: 使用的SDK路径
-c: 生成目标文件,只运行preprocess,compile,assemble,不链接
-o: 输出文件
\ : 终端换行符

TestExample.o —> libTestExample.a

#方法一
ar -rc libTestExample.a TestExample.o
#方法二 Xcode用法
libtool -static -arch_only x86_64 TestExample.o -o libTestExample.a

命令:
ar:压缩目标文件,并对其进行编号和索引,形成静态库。同时也可以解压缩静态库,查看有哪些目标文件:
-r: 像a.a添加or替换文件
-c: 不输出任何信息
-t: 列出包含的目标文件

test.m 链接一个静态库StaticLibrary(libTestExample.a)

image.png

test.m —> test.o

clang -x objective-c \
-target x86_64-apple-macos11.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk \
-I./StaticLibrary \
-c test.m -o test.o

命令:
-I: 在指定目录寻找头文件 (header search path)

test.o —> test.exec

clang -target x86_64-apple-macos11.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk \
-L./StaticLibrary \
-lTestExample \
test.o -o test

命令:
-L: 指定库文件路径(.a.dylib库文件) library search path
-l: 指定链接的库文件名称(.a.dylib库文件)other link flags -lAFNetworking

查看效果

image.png
lldb
file test
r

Build.sh脚本执行

image.png
综合上述代码后,sh中的一部分代码:

pushd ./StaticLibrary (进入文件目录)
popd (返回

执行脚本

./build.sh

#zsh: permission denied: ./build.sh 报错后 需要增加可执行权限
chmod -x ./build.sh
#或者这样 u代表所有者
chmod u+x build.sh

test.m 链接一个Frameworks(TestExample.framework/Headers/TestExample.h)
TestExample.framework/TestExample文件是libTestExample.a去掉lib和.a

image.png

test.m —> test.o

clang -x objective-c \
-target x86_64-apple-macos11.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk \
-I./Frameworks/TestExample.framework/Headers \
-c test.m -o test.o

test.o —> test.exec

clang -target x86_64-apple-macos11.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk \
-F./Frameworks \
-framework TestExample \
test.o -o test

-F: 在指定目录寻找framework framework search path
-framework: 指定链接的framework名称 other link flags -framework AFNetworking

相关文章

  • 目录一、库二、静态库、动态库、Framework三、打包静态库 1、.a静态库和.framework静态库的区别 ...

  • iOS静态库之间互调冲突问题

    研究目的 1. 在其他静态库(B静态库)中导入公共静态库(A静态库),想直接使用公共静态库(A静态库)中的方法和m...

  • iOS小知识 -- 静态库(一)

    静态库静态库的介绍.a静态库的制作以及测试静态库的架构问题.framework静态库的制作以及测试边开发边制作静态...

  • 静态库

    静态库 静态库动态库简介 .a 静态库:被编译好的二进制文件 静态库:.a, .framework 动态库: .d...

  • Ndk生成so和a库,然后主项目进行调用

    在 NDK 开发中引入第三方静态库和动态库 静态库和动态库 静态库 静态库文件后缀一般为 .a ,利用静态库编译成...

  • iOS 静态库和动态库的制作

    静态库和动态库 一、静态库和动态库的存在形式 静态库: .a 和 .framework 动态库: .dylib 和...

  • ios中静态库.a的制作

    在ios中制作静态库之前,先来了解关于静态库的一些概念。 八、静态库和动态库在使用上的区别。静态库:链接时,静态库...

  • ios中静态库.a的制作和使用

    在ios中制作静态库之前,先来了解关于静态库的一些概念。 八、静态库和动态库在使用上的区别。静态库:链接时,静态库...

  • iOS 静态库

    iOS 静态库 iOS 静态库

  • 静态库和动态库

    静态库和动态库的存在形式静态库:.a 和 .framework动态库:.dylib 和 .framework 静态...

网友评论

      本文标题:静态库

      本文链接:https://www.haomeiwen.com/subject/bmigzktx.html