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.

Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
  • Have you checked `Build for active architectures only` in `Build Settings` ? – olha Oct 01 '20 at 09: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. – Sazzad Hissain Khan Oct 01 '20 at 09: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 Jan 12 '21 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 Jan 30 '21 at 04:55
  • Did you ever solve this? Banging my head against the wall for days now. – swiftyboi Jan 19 '22 at 20:23

2 Answers2

3

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.

Eugene Dudnyk
  • 5,553
  • 1
  • 23
  • 48
  • 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 Jan 30 '21 at 04: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. – Eugene Dudnyk Jan 30 '21 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 Feb 01 '21 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. – Eugene Dudnyk Feb 11 '21 at 22:03
1

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

Deeksha gupta
  • 659
  • 6
  • 15