-1

I am building a static library to be used with another project I'm working on, and eventually it will be included in a framework I'm developing. When I bring the library into my project, the arm builds work fine, but the simulator builds fail with missing symbols for the x86_64 build. I have set the build architectures in the library to

arm64 arm64e armv7 armv7s x86_64

I have tried various settings, like $(ARCHS_STANDARD) to no avail. I have also tried all of the potential solutions I could find on SO, most of which are pretty old.

Any and all suggestions would be greatly appreciated.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
SteveB
  • 483
  • 1
  • 4
  • 18
  • You have to build for each architecture separately and then lipo them together into a fat binary. See for example https://agilewarrior.wordpress.com/2016/12/22/how-to-create-universal-static-library-ios/ or https://medium.com/@hassanahmedkhan/a-noobs-guide-to-creating-a-fat-library-for-ios-bafe8452b84b – matt Feb 20 '19 at 15:47
  • The first link is germane to my question, but unfortunately it doesn't work. The date on the post is December 2016, so I assume it refers to Xcode 9. I did find the library it created in the derived data folder, and it was twice as big as the other one, but I still get the linker errors. I will try to manually lipo the files it did create and report back here. – SteveB Feb 20 '19 at 17:06
  • Doing the manual lipo actually did work. The script provided in the link has to be modified to prevent an error (remove "include" from the cp line at the end), but it still didn't build a universal file. The manual lipo had to be done. @matt, if you post your comment as an answer and reference this comment, I will accept it as the answer. – SteveB Feb 20 '19 at 17:36
  • I don't see why this isn't a duplicate. You said "I have also tried all of the potential solutions I could find on SO", but evidently that's not true, because calling `lipo -create` is one of those solutions. – matt Feb 20 '19 at 17:55
  • For example https://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4 – matt Feb 20 '19 at 17:57
  • And https://stackoverflow.com/questions/35645372/unable-to-create-ios-static-library-a-file-using-make-command – matt Feb 20 '19 at 17:58
  • And https://stackoverflow.com/questions/50887690/generating-a-fat-library-from-a-static-library – matt Feb 20 '19 at 17:58
  • Possible duplicate of [Generating a fat library from .a static library](https://stackoverflow.com/questions/50887690/generating-a-fat-library-from-a-static-library) – matt Feb 20 '19 at 17:59
  • Voting to close as a duplicate, on that basis. – matt Feb 20 '19 at 17:59
  • Because I was unaware that I needed to build a fat library. If I had searched for fat library, I would have found those posts, but since I searched for missing x86_64 symbols, I didn't. Hopefully, this will help someone to find the answer if they went at it the same way I did. – SteveB Feb 20 '19 at 18:23
  • Well, I suggest then that you answer your own question. That's perfectly legal and will serve your goal of helping others (assuming the question doesn't get closed down as a duplicate). – matt Feb 20 '19 at 19:03

1 Answers1

0

As mentioned in the comments and the edit, you have to build a fat library, but there are steps missing in all of the answers and many of them are badly out of date. Hopefully this will help.

  1. Build a version of the static library for iPhoneOS and iPhoneSimulator.
  2. On the command line, cd to the derived data directory for your project.
  3. You will see directories for the OS and simulator libraries.
  4. Execute the lipo command as below

    lipo -create -output [desired fat library name] [path to iPhoneOS library] [path to iPhoneSimulator library]

  5. Drag the fat library from finder to your target project.

You can probably automate this with a build script, but I was under a deadline so it was faster to just build and drag. If you come up with a good script, feel free to post it here.

P.S. The script presented in the Agile Warrior post did not work.

SteveB
  • 483
  • 1
  • 4
  • 18