6

Getting linker error in Xcode 12 when I am trying to build my large iOS app (hybrid, swift+objc). The application is building fine for real device, but It gives linker error when I am trying to run in Simulator directly with Debug configuration.

I have tried all possible solutions in other post here, but unfortunately it didn't work. Although the error in other post is different. I have checked Build for active architectures only to YES for Debug configs and NO for Release configs.

Other post error,

building for iOS Simulator, but linking in object file built for iOS, for architecture arm64

My error,

building for iOS Simulator, but linking in object file built for macOS, file for architecture x86_64

How can I resolve this issue? I need to run in both iOS real device and Simulator.

5
  • Have you checked Build for active architectures only in Build Settings ?
    – olha
    CommentedOct 1, 2020 at 9:52
  • 1
    @Olha I have checked Build for active architectures only to YES for Debug configs and NO for Release configs. The application is building fine for real device, but It gives linker error when I am trying to run in Simulator directly with Debug configuration.CommentedOct 1, 2020 at 9:56
  • This is lacking a bit of info that might be important to answer: I assume you get this linker error from an included framework, maybe a cocoapod? Or is it a precompiled framework/library you include? As you say you have an iOS app (I guess hybrid was only referring to the languages) it's weird you even see the macOS arch in there at all. Depending on how the framework is included in your project you might have to strip it out in a custom build phase (using lipo) yourself, but without further info I can't say that.
    – Gero
    CommentedJan 12, 2021 at 10:02
  • I get the same error from a precompiled Fat binary, runs on device, errors out on simulator, I have been searching for a workaround for weeks now but no success and the owner of the third party library is not updating it basically putting a nail in our progress
    – Ramin
    CommentedJan 30, 2021 at 4:55
  • Did you ever solve this? Banging my head against the wall for days now.
    – swiftyboi
    CommentedJan 19, 2022 at 20:23

2 Answers 2

5

Wherever you got your library you should request the library that is compiled for iOS Simulator, not for macOS, although they have the same binary architectures that are returned via lipo -info <file>.

You can verify that your static (.a) or dynamic library (.dylib) is compiled for iOS Simulator using this command:

otool -l <path-to-library> | grep platform 

The output means the following:

  • platform 7 - iOS Simulator
  • platform 6 - Mac Catalyst
  • platform 4 - watchOS
  • platform 2 - iOS
  • platform 1 - macOS

Here is the full definition of the enum for platform.

4
  • Doing this I get nothing back, what does that mean? The fat binary I am using is supposed to be compiled for both iOS Simulator and macOS which is I guess why I have the same error but I don't get ant results from running this otool command
    – Ramin
    CommentedJan 30, 2021 at 4:58
  • Is the fat binary that you refer to, located inside the framework? If so, the cmd LC_BUILD_VERSION section is not present in the binary, and the information from it is located in the Info.plist of the framework.CommentedJan 30, 2021 at 17:05
  • No its not in the framework, just two .a files that are created the old fashion way. The original producer of the binary apparently is too busy to create a new one after two years while selling this to people!
    – Ramin
    CommentedFeb 1, 2021 at 15:22
  • @Ramin then it was probably compiled with the older clang version that did not specify this information in the binary. And the newer version is looking for it during linkage. What you can try to do is to add this info into the binary by yourself via some hex editor. I can’t think of other solution to your situation.CommentedFeb 11, 2021 at 22:03
1

Try to add x86_64 in VALID_ARCHS in the User-defined section in Build Settings. enter image description here

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.