How can I use .a static library in swift?

I want to use the old webrtc.a library in swift. You can help? I read that you cannot use static libraries in swift, is that true?

+17
source share
4 answers

Have you fixed this problem? I also encounter this problem, and I fixed it for a moment. If you have not fixed this problem, you can try the following steps:

ps: 2 projects are in the same workspace (static lib project and application project), a static lib project is built before the application project. Workspace structure as shown in the figure:

/ Users / raniys / Desktop / Screen Shot 2016-03-14 at 5.27.20 PM.  PNG

  • In a static lib project, all .h files must be added to "Build Phases / Copy Files":

enter image description here

  1. lib ( .a) , . .

(: " / / " )

enter image description here

*, .a, " iOS" lib .a app project ( )

  1. " " :

enter image description here

.a, : $(USER_LIBRARY_DIR)/Developer/Xcode/DerivedData/StockApp-fkjqyvsniiauxogkivalcduqeotj/Build/Products/Debug-iphoneos

  1. Bridging-Header lib, "StaticLib/StaticLib.h" "CommonFoundation/CommonFoundation.h":

enter image description here

  1. Bridging-Header "Objective-C Bridging Header" :

enter image description here

, . enter image description here

+33

Objective C Swift

(Mixing Swift Objective-C ), bridging header, Objective C Swift. [Mixing Swift and Objective-C code in a project]

, Objective-C Swift

Swift customer → Objective-C

Xcode 10.2.1

Objective-C

File -> New -> Project... -> Cocoa Touch Static Library
//or
Project editor -> Add a Target -> Cocoa Touch Static Library 

module.modulemap[About]

module module_name {
    umbrella header "module_name-umbrella.h"
    export *
}

module_name-umbrella.h[About] .h,

#import "header_1.h"
#import "header_2.h"

module.modulemap module_name-umbrella.h Copy Files[About].

Project editor -> select a target -> Build Phases -> Copy Files -> add 'module.modulemap', 'module_name-umbrella.h' 

.m

Select '.m' file -> Select File Inspectors Tab -> Target Membership -> Select the target
//or
Project editor -> select a target -> Build Phases -> Compile Sources -> add files

.h, module_name-umbrella.h (header_1.h, header_2.h)[can not do it] [public target membership]

Select '.h' file -> Select File Inspectors Tab -> Target Membership -> Select the target and make it **public**
//or
Project editor -> select a target -> Build Phases -> Headers -> add files to the **public** zone

- ⌘ Command + B Product -> Build

. , , .

[Build location]

Products group -> lib<product_name>.a -> Show in Finder

  • lib<product_name>.a -
  • include/<product_name> Copy Files
  • usr/local/include Headers. /

Objective-C

Drag and drop Xcode[About]

Link Library[Undefined symbols] [Link vs Embed]

Project editor -> select a target -> General -> Linked Frameworks and Libraries -> add -> Add Others... -> point to 'lib<product_name>.a' file
//or
Project editor -> select a target -> Build Phases -> Link Binary With Libraries -> add -> Add Others... -> point to 'lib<product_name>.a' file

Library Search paths[Library not found for] [Recursive path]

Project editor -> select a target -> Build Settings -> Search Paths -> Library Search paths -> add path to the parent of 'lib<product_name>.a' file

Header Search Paths[Module not found] [Recursive path]

Project editor -> select a target -> Build Settings -> Search Paths -> Header Search Paths -> add path to generated 'include/<product_name>' folder with 'module.modulemap' and '<product_name>-umbrella.h'

Swift[module_name]

import module_name

+2

, Swift. " " .

enter image description here

" ", " " " ", , .a .

enter image description here

, " "

, Objective-C, Swift Bridging.

+1

Xcode 9 , Swift. Objective-C. XCode

Xcode supports static target libraries that contain Swift code. Debugging applications using static Swift libraries may require a full set of build artifacts that are in their original location.

+1
source

Source: https://habr.com/ru/post/1690673/


All Articles