Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using bridging headers with module interfaces is unsupported (XCode)

Tags:

xcode

swift

I have an XCode (Swift) project which is using native static lib (Swift) and this lib uses another native static lib (C++)

static lib A (C++) -> static lib B (Swift) -> MyProject

first of all, in order to be able to use methods from lib A in lib B, I need to set the bridge file in the BuildSettings, right? then I am free to use any methods from A in B, ok.

If I try to build the lib B with Build libraries for distribution = NO, everything is compiling and works, but if I need to change this value to YES (in order to distribute the lib as Release ver) I get the error

error: using bridging headers with module interfaces is unsupported

After a little google I found a few possible solutions on SO where most of them suggest setting Build libraries for distribution = NO, but this solution looks for me as a workaround, because in order to distribute the lib as a Release version you need to set it as YES.

Then I found another solution

https://developer.apple.com/forums/thread/10419

but here one explains that

You'll need to remove the bridging header from where you added it in the Build Settings, in order to get your framework to compile.

But I can't remove the bridge file as if I remove it I don't be able to use lib A in my lib B.

So, what is the proper solution here?

like image 337
Aleksey Timoshchenko Avatar asked Mar 20 '26 18:03

Aleksey Timoshchenko


1 Answers

Yes, you can not use bridging header in a swift framework, but there is some workaround. Use Module!

  1. create module map file for libA. for example, lib A is
@interface LibA : NSObject
+ (void)testA;
@end

so you can create map file like this:

module LibA {
    header "LibA.h"
    export *
}

just be careful the path

header "xxx/libA.h", 
  1. Set the build setting search paths for frameworkB

add search paths in Build Settings - Swift Compiler - Search Paths - Import Paths

$(SRCROOT)/FrameworkB/

  1. use LibA in frameworkB

full example in github

like image 174
kun wang Avatar answered Mar 22 '26 07:03

kun wang