# 编译test.m -> test.o
clang -target x86_64-apple-macos12.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk \
-I./AFNetworking \
-c test.m -o test.o
# 链接test.m -> AFNetworking动态库
clang -target x86_64-apple-macos12.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk \
-L./AFNetworking \
-lAFNetworking \
test.o -o test
# 调试
➜ 链接动态库AFN file test
test: Mach-O 64-bit executable x86_64
➜ 链接动态库AFN lldb
(lldb) file test
Current executable set to '/Users/joe.cheng/Video/动态库/上课代码/链接动态库AFN/test' (x86_64).
(lldb) r
# 动态库原理
# 编译test.m -> test.o
clang -target x86_64-apple-macos12.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk \
-I./dylib \
-c test.m -o test.o
# 编译TestExample.m -> TestExample.o
clang -target x86_64-apple-macos12.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk \
-c TestExample.m -o TestExample.o
# 链接TestExample.o -> libTestExample.dylib
## 1. 方式1
clang -dynamiclib \
-target x86_64-apple-macos12.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk \
TestExample.o -o libTestExample.dylib
## 2.1 方式2(官方)
libtool -static -arch_only x86_64 TestExample.o -o libTestExample.a
# -lsystem -framework Foundation 指定系统库
# mach-o 添加image path,否则image not found
## 2.2 方式2(官方)
ld -dylib -arch x86_64 \
-macosx_version_min 12.1 \
-syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk \
-lsystem -framework Foundation \
-ObjC \
-install_name /Users/joe.cheng/Video/动态库/上课代码/动态库原理/dylib/libTestExample.dylib \
libTestExample.a -o libTestExample.dylib
## ld -dylib -arch x86_64 -macosx_version_min 12.1 libTestExample.a -o libTestExample.dylib
## 2.2 会引起image not found
ld -dylib -arch x86_64 \
-macosx_version_min 12.1 \
-syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk \
-lsystem -framework Foundation \
-ObjC \
libTestExample.a -o libTestExample.dylib
# 链接test.o -> libTestExample.dylib
clang -target x86_64-apple-macos12.1 \
-fobjc-arc \
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk \
-L./dylib \
-lTestExample \
test.o -o test
编译链接动态库
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 以下内容都是对于源文件main.c 静态链接库(Static Link Library) 静态链接库文件中包含函数...
- 该动态编译可以生成一个DTO类 1.创建一个控制台项目 2.新建一个c#类,一个Dto类 3.运行控制台项目 运行...
- 以后没啥好图,封面就上小姐姐图了 这次书接上回,前段时间写了一篇《使用cmake构建C/C++项目和动态库》的文章...