如何在swift中使用.a静态库? [英] How can I use an .a static library in swift?

查看:2028
本文介绍了如何在swift中使用.a静态库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在swift中使用我的webrtc .a静态库。你能帮帮忙吗?我读过你不能在swift中使用静态库,这是真的吗?

I want to use my webrtc .a static library in swift. Can you help please? I read you can´t use static libraries in swift, is that true?

推荐答案

你修复过这个问题吗?我今天也遇到了这个问题,我已经修好了一会儿。如果您没有解决此问题,可以尝试以下步骤:

Have you fixed this problem you asked? I meet this problem on today too, and I've fixed it just a moment. If you don't have fixed this problem, you can try the below steps:


ps:2个项目位于同一个工作区(静态lib项目和App项目),静态lib项目是在app项目之前构建的。工作区结构如图所示:

p.s.: the 2 projects are in the same workspace (the static lib project and the App project), the static lib project is build before the app project. The workspace structure as the pic shows:



  1. 在静态lib项目中,所有.h文件都是需要添加到构建阶段/复制文件:




  1. 将静态lib产品文件(.a文件)拖到应用项目,请参阅图片:

(路径:app project / Build Phase / Link Binary with Libraries)

(path: "app project/Build Phases/Link Binary With Libraries")


*如果你关心.a文件的红色标记,你只需要选择通用iOS设备作为构建设备重新构建静态lib项目,并将.a重新拖动到app项目(红色可以删除)

*if you care about the red color mark for the .a file, you just need choose the "generic iOS device" as the build device to re-build the static lib project, and re-drag the .a to the app project(the red one can be delete)


  1. 在您的应用项目中设置图书馆搜索路径:



这是.a文件路径项目内置:$(USER_LIBRARY_DIR)/ Developer / Xcode / DerivedData / StockApp-fkjqyvsniiauxogkivalcduqeotj / Build / Products / Debug-iphoneos

this is the .a file path which the project built in: $(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/StockApp-fkjqyvsniiauxogkivalcduqeotj/Build/Products/Debug-iphoneos


  1. 为您的应用项目创建Bridging-Header文件,并在其中导入静态库,在我的情况下,我包含StaticLib / StaticLib.h和CommonFoundation / CommonFoundati on.h:




  1. 将Bridging-Header文件路径添加到应用项目的Objective-C Bridging Header :


然后全部完成,您现在可以使用静态库的功能。

Then all done, you can use the functions of the static libraries now.

这篇关于如何在swift中使用.a静态库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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