简体   繁体   中英

Linker architecture error using C library inside Swift module

I have an xcode workspace with the following structure:

  • AC library iGLPK compiled into a framework (dynamic or static, the error persists)

  • A dynamic framework SwiftyGLPK which has iGLPK as a linked framework and provides a Swift wrapper to use the C library

  • An xcode project Frozen which has SwiftyGLPK as a linked framework

  • The code that uses the SwiftyGLPK library is in a separate framework target Model_GLPK within the Frozen project. This framework compiles fine.

The problem comes when I write code within the main Frozen/ViewController that calls on Model_GLPK and hence down to the C library underneath - it does not compile and produces this linker error:

Undefined symbols for architecture arm64:
  "SwiftyGLPK.SolveGoal.Minimise (SwiftyGLPK.SolveGoal.Type) -> SwiftyGLPK.SolveGoal", referenced from:
  Frozen.ViewController.viewDidLoad (Frozen.ViewController)() -> () in ViewController.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I get the same result on the simulator and on device, just the architecture that's not found changes.

I also tried extracting the files from the Model_GLPK framework and putting them directly into the Frozen target. Now everything compiles fine and there is no longer a linking error, but instead I get a hard crash on run

dyld`dyld_fatal_error:
->  0x1200c1088 <+0>: brk    #0x3

after this instruction:

dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*)

Can anyone shed light on what's going on?

I found a solution, but not an explanation.

I built up the workspace step by step again, starting from having the C library compiled directly inside the main project which worked, then extracting it into a framework, then extracting its Swift wrapper into its own framework, then creating an internal module linked to the wrapper.

Now everything works but I still have no idea why or what's different from before. The whole thing feels really fragile. ¯_(ツ)_/¯

This article on module maps for static libraries was helpful, as was this one . Also this build settings reference .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM