-
Notifications
You must be signed in to change notification settings - Fork 4
Auto Link
ShenYj edited this page Feb 10, 2022
·
2 revisions
LC_LINKER_OPTION
: 链接器的特性 Auto-Link
启用这个特性后,当我们import <模块>
,不需要我们再去往链接器去配置链接参数。
比如import <framework>
我们在代码里使用这个是framework格式的库文件,那么在生成目标文件时,会自动在目标文件的Mach-O
中,插入(编译阶段)一个 load command
,格式是LC_LINKER_OPTION
,存储这样一个链接器参数-framework <framework>
-
准备代码
#import <Foundation/Foundation.h> int main() { return 0; }
-
编译
.o
脚本, 增加了一个-fmodules
参数clang -x objective-c -fmodules \ -target x86_64-apple-macos11.1 \ -fobjc-arc \ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk \ -I./Frameworks/TestExample.framework/Headers \ -c test.m -o test.o
-
otool
查看.o
otool -l /Users/shenyj/Documents/CodeForTest/lib/staticLib/test.o
输出结果:
/Users/shenyj/Documents/CodeForTest/lib/staticLib/test.o: Load command 0 cmd LC_SEGMENT_64 cmdsize 392 segname vmaddr 0x0000000000000000 vmsize 0x0000000000000078 fileoff 856 filesize 120 maxprot 0x00000007 initprot 0x00000007 nsects 4 flags 0x0 Section sectname __text segname __TEXT addr 0x0000000000000000 size 0x000000000000000f offset 856 align 2^4 (16) reloff 0 nreloc 0 flags 0x80000400 reserved1 0 reserved2 0 Section sectname __objc_imageinfo segname __DATA addr 0x000000000000000f size 0x0000000000000008 offset 871 align 2^0 (1) reloff 0 nreloc 0 flags 0x10000000 reserved1 0 reserved2 0 Section sectname __compact_unwind segname __LD addr 0x0000000000000018 size 0x0000000000000020 offset 880 align 2^3 (8) reloff 976 nreloc 1 flags 0x02000000 reserved1 0 reserved2 0 Section sectname __eh_frame segname __TEXT addr 0x0000000000000038 size 0x0000000000000040 offset 912 align 2^3 (8) reloff 0 nreloc 0 flags 0x6800000b reserved1 0 reserved2 0 Load command 1 cmd LC_BUILD_VERSION cmdsize 24 platform 1 minos 11.1 sdk 12.1 ntools 0 Load command 2 cmd LC_SYMTAB cmdsize 24 symoff 984 nsyms 1 stroff 1000 strsize 8 Load command 3 cmd LC_DYSYMTAB cmdsize 80 ilocalsym 0 nlocalsym 0 iextdefsym 0 nextdefsym 1 iundefsym 1 nundefsym 0 tocoff 0 ntoc 0 modtaboff 0 nmodtab 0 extrefsymoff 0 nextrefsyms 0 indirectsymoff 0 nindirectsyms 0 extreloff 0 nextrel 0 locreloff 0 nlocrel 0 Load command 4 cmd LC_LINKER_OPTION cmdsize 40 count 2 string #1 -framework string #2 Foundation Load command 5 cmd LC_LINKER_OPTION cmdsize 40 count 2 string #1 -framework string #2 CoreGraphics Load command 6 cmd LC_LINKER_OPTION cmdsize 40 count 2 string #1 -framework string #2 CoreServices Load command 7 cmd LC_LINKER_OPTION cmdsize 32 count 2 string #1 -framework string #2 IOKit Load command 8 cmd LC_LINKER_OPTION cmdsize 40 count 2 string #1 -framework string #2 DiskArbitration Load command 9 cmd LC_LINKER_OPTION cmdsize 40 count 2 string #1 -framework string #2 CFNetwork Load command 10 cmd LC_LINKER_OPTION cmdsize 32 count 2 string #1 -framework string #2 Security Load command 11 cmd LC_LINKER_OPTION cmdsize 40 count 2 string #1 -framework string #2 CoreFoundation
可以看到多出很多LC_LINKER_OPTION
的 load command
这也是 xcode
默认执行的操作, Xcode 设置路径:
ShenYj.github.io - 简书地址 - 返回首页
-
Apple
Common
蓝牙
LBS
音视频
- AVAudioSessionchange_route
- 切换线路
- StreamingKit
- Audio Unit 基础
OC 与 Swift 混编
Object-C
- 代码混淆
- autoreleasepool
- 忽略编译器(clang)警告
- 定时器
- 锁
- RunLoop
- block
- NS_REFINED_FOR_SWIFT
- NS_CLOSED_ENUM
- NS_TYPED_ENUM、NS_STRING_ENUM
- NS_TYPED_EXTENSIBLE_ENUM、NS_EXTENSIBLE_STRING_ENUM
- 关键字nonnull和nullable
- class、objc_getClass和object_getclass方法区别
- isKindOfClass和isMemberOfClass
- 应用程序的加载
- non-lazy classes & lazy classes
- load方法
- initialize方法
- 方法的本质
- 类型编码
- self和super
- 类的内存分析
Swift
- precondition
- 权限控制
- Array常用Api
- String初始化、定义
- String常用Api
- String截取演练
- Set定义、创建
- Set访问和修改
- Dictionary操作
- Dictionary和KeyValuePairs
- Dictionary与String转换
- 常用高阶函数
- enum原始值
- enum关联值
- enum遍历
- 递归enum
- enum内存分配
- 指针
- for循环
- break跳出循环
- 变量名与关键字冲突
- 类的定义
- 类的继承和初始化
- 关键字: final
- 关键字: mutating
- 关键字: lazy
- 修饰类方法的关键字: static
- 关键字: final、dynamic、objc和_dynamicReplacement
- 关键字:@dynamicMemberLookup和@dynamicCallable
- 关键字: propertyWrapper
- 自定义运算符
- 下标: subscript
- 扩展: extension
- 协议: protocol
- 协议和扩展
- 为什么需要泛型
- 泛型函数定义
- 泛型类型
- 泛型的类型约束
- 关联类型
- 为泛型定义要求
- 泛型下标
- 多线程
- Attributes
- 错误处理
- Codable
- DispatchSourceTimer
- Swift 5.x 演练: 更多功能编辑页
- Swift 5.x 类库收集
- 单元测试笔记
- 实例对象内存结构
- 元类型、Type、Self
- frozen
- convention
- Swift(5.3.2)源码编译
- SQLite.Swift类库演练
- Swift 5.5 关键字: async/await
- Swift 5.5 新特性: Continuations
- Swift 5.5 新特性: Actor
- Swift 方法调度
- Swift Mirror
- Swift 关键字: @_silgen_name
- Swift 关键字: @_disfavoredOverload
- swiftmodule
- Swift 5.6 新特性: Type placeholders
- Swift 5.6 新特性: #unavailable
- Swift 5.6 新特性: CodingKeyRepresentable
- Swift 5.6 新特性: existential any
- Swift 5.7 新特性: if-let/guard 语法简化
- Swift 5.7 新特性: Multi-statement closure type inference
- Swift 5.8 新特性: @backDeployed
- Swift 5.9 新特性: if switch expressions
- Swift 6.0 新特性:@preconcurrency
RxSwift
macOS - AppKit
-
iOS Assembly(ARM64)
-
C++
C++ 基础
- cout、cin
- 函数重载
- 默认参数
- extern "C"
- pragma once
- inline function
- const
- Reference
- 汇编
- 类和对象
- 堆空间内存管理
- Constructor
- Destructor
- 成员变量初始化
- 声明与实现分离
- namespace
- 继承
- 访问权限
- 初始化列表
- 多态:虚函数
- 多态:虚函数实现原理
- 多态:虚析构函数
- 多态:纯虚函数
- 多态:抽象类
- 多继承
- static
- static: 单例模式
- const 成员
- 引用类型成员
- 拷贝构造函数
- 调用父类的拷贝构造函数
- 浅拷贝、深拷贝
- 对象型参数和返回值
- 匿名对象
- 隐式构造
- 编译器自动生成的构造函数
- 友元
- 内部类
- 局部类
- 运算符重载
- 模板
- 类型转换
- C++标准
- Lambda
- 异常
- 智能指针
-
Flutter
Dart
Flutter
-
Go
Go 基础
-
Ruby
Ruby 基础
-
React-Native
React-Native
-
工具篇
-
Swift Package Manager
-
自动化
-
TroubleShooting
-
扩展