Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It gives errors when using Swift Static library with Objective-C project

I need to make swift static library for my requirement. I made swift static library which uses swift and Obj-c code. I have included Obj-c files via bridge file. I am able to compile swift static library without any error and get libMySwift.a file. I use Xcode9.3 with Swift4 to compile library.

I include libMySwift.a in obj-c project and also included obj-c compatible header to access my lib in the project. When I try to compile the project it give below warning and more than 200 errors.

Auto-Linking library not found for -lswiftSwiftOnoneSupport Auto-Linking library not found for -lswiftCore Auto-Linking library not found for -lswiftQuartzCore Auto-Linking library not found for -lswiftCoreImage Auto-Linking library not found for -lswiftCoreGraphics Auto-Linking library not found for -lswiftObjectiveC Auto-Linking library not found for -lswiftDispatch Auto-Linking library not found for -lswiftMetal Auto-Linking library not found for -lswiftFoundation Auto-Linking library not found for -lswiftUIKit Auto-Linking library not found for -lswiftDarwin Auto-Linking library not found for -lswiftCoreFoundation 

Please let me know if I am missing any steps or need to add anything.

like image 770
Vishal Gabani Avatar asked Apr 30 '18 07:04

Vishal Gabani


People also ask

Can I use Swift library in Objective C?

The Swift library cannot be directly called from Objective-C, since it is missing the required annotations in the code, and in many cases, modules do not inherit from NSObject, rather they use the native Swift data types.

What is static library in Swift?

What is a static library? A static library is a collection of compiled source code files. Let's say we have FileA. swift , FileB. swift and FileC.

Does Swift support static libraries?

As mentioned, Apple does allow Swift in static libraries as of Xcode 9 Beta 4.


1 Answers

I've got the same error on my demo project when added first Swift file in my pod compiled as static library. For me solution was simple - just added empty Swift file to my demo project which was previously in Objective-C only. This solved all linker errors.

like image 55
Alex Roslyakov Avatar answered Sep 21 '22 23:09

Alex Roslyakov