# 编译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
编译链接动态库
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 以下内容都是对于源文件main.c 静态链接库(Static Link Library) 静态链接库文件中包含函数...
- 该动态编译可以生成一个DTO类 1.创建一个控制台项目 2.新建一个c#类,一个Dto类 3.运行控制台项目 运行...
- 以后没啥好图,封面就上小姐姐图了 这次书接上回,前段时间写了一篇《使用cmake构建C/C++项目和动态库》的文章...