Xcode 11.4 : Building for iOS Simulator but the linked library was built for Mac OS + iOS

In Xode 11.4, I encounter a failure in my project.

When running my project, it was successfull in Xcode 11.3. Now in Xcode 11.4 I get the failure message:

Target Integrity: Building for ios simulator but the linked library ' my_library.a ' was built for may OS + ios.


The library " my_library.a is pointed to architecture: x86_64 and arm64 and never changed

I can run the Project on my device, but it is not running in the simulator.


Please help me what to do in Xcode 11.4. Do I have to change settings in Xcode 11.4.


regards, Robert

Accepted Reply

Having x86_64 code is not sufficient to distinguish if a binary is intended for the iOS Simulator, a macOS app, or a Mac Catalyst app. Combing built binaries across different destinations (which includes the simulator vs. device binaries) is not a supported combination -- there is no Apple platform where ARM code and x86_64 code in the same binary is a correct configuration.


If this is your library, you should have your app build it from source as a dependency of your Xcode project, either through an Xcode target or through Swift Package Manager, so that the right platform information is included based on the build target.


If this is your library but you have a specific reason for it to be pre-compiled, please build it as an XCFramework. XCFrameworks correctly separate out binaries that have the right architectures for the different platforms you target. In addition to instructions on how to build such a XCFramework linked earlier, we have a WWDC talk illustrating it.


If this library is from a framework vendor (either as source or a pre-compiled binary), or you integrate a vendor's library into your app with a third party dependency manager, please consult with the library vendor or dependency manager for support.

Replies

I have the same problem.


"error: Building for iOS Simulator, but the linked library 'lib.a' was built for iOS. "


We have some lib only used in generic device and would not called in Simulator. It was work in Xcode 11.3, but not in Xcode 11.4.


I can use the legacy build system to resolve this error. But I think it's not the good solution.

I add "***.a" to "EXCLUDED_SOURCE_FILE_NAMES" in "Any iOS Simulator SDK" resolve my compile error.

Have done your advice, but when I exclude the library and start the program, I get a lot of linking failure messages from that library. It seems that the ios Simulator needs the static library. Everything was fine in Xcode 11.3 and no more in Xcode 11.4

Having x86_64 code is not sufficient to distinguish if a binary is intended for the iOS Simulator, a macOS app, or a Mac Catalyst app. Combing built binaries across different destinations (which includes the simulator vs. device binaries) is not a supported combination -- there is no Apple platform where ARM code and x86_64 code in the same binary is a correct configuration.


If this is your library, you should have your app build it from source as a dependency of your Xcode project, either through an Xcode target or through Swift Package Manager, so that the right platform information is included based on the build target.


If this is your library but you have a specific reason for it to be pre-compiled, please build it as an XCFramework. XCFrameworks correctly separate out binaries that have the right architectures for the different platforms you target. In addition to instructions on how to build such a XCFramework linked earlier, we have a WWDC talk illustrating it.


If this library is from a framework vendor (either as source or a pre-compiled binary), or you integrate a vendor's library into your app with a third party dependency manager, please consult with the library vendor or dependency manager for support.

in case your project is only targeting iOS + iOS simulator it should be sufficient if your dependencies are recompiled with Xcode 11, like edford mentioned it in another thread (https://forums.developer.apple.com/thread/117346)

Thanks for the info.

But I did not get the library running by changes in Xcode settings. So, I tried to recompile it in xcode 11.4

The library is a static C-Library. . So, c-code has to be compiled and linked. I have done it before and library was running in Xcode 11.3


in the MAKE file I adjusted:

CC = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc

CFLAGS = -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk

When I run it, I receive a new library. This library is arch: X86_64 and arm64

But even with this new created library in my project I get the same mistake:

"Building for ios simulator , but the linked library was build for macOS + ios


Then I changed the CFLAGS to the iphone simulator platform:

CFLAGS = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.4.sdk


Problem is that I do not know what is the arch for the Simulator ?


Can You help me to adjust the CFLAGS settings or other adjustments in the MAKE File to receive a library accepted by the simulator ?

Thanks, Robert

That hasn't helped me. I've rebuilt my libraries (forked existing libraries that weren't supported anymore, imported them into Xcode 11.4) - I can still run the app just fine on the device but building for the simulator fails every time with the same error.

The supported methods of building the library to ensure the right combinations of architectures and platforms are through an Xcode project or a Swift Package.

What xcodebuild command did you use to rebuild the libraries?

In Your answer before, You adviced me to create the library through an xcode project or a Swift package..


I give you first here the info, how I have done it actually

To create the library , I did the following steps:

I have some -.c files that have to be compiled and linked to get the library.

for all that I use the Terminal :

1. I gave the -.c files in a folder /usr/local/f2c/libf2c

2. I modified the makefile on CC and CFLAGS to adjust for the Xcode settings

here some extracts of the makefile:

.SUFFIXES: .c .o

CC = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc"

SHELL = /bin/sh

CFLAGS = -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk


# compile, then strip unnecessary symbols

.c.o:

$(CC) -c -DSkip_f2c_Undefs $(CFLAGS) $*.c. # HERE the COMPILING starts

ld -r -x -o $*.*** $*.o

mv $*.*** $*.o

.....

all: f2c.h signal1.h sysdep1.h libf2c.a

........


libf2c.a: $(OFILES)

ar r libf2c.a $?

-ranlib libf2c.a

3. I call ' make ' in the terminal and then the sript is running

Result is a library called : libf2c.a

to check the library by : lipo -info libf2c.a

this library is architecture X86_64 and arm64, same as before, when I created it with previous MAC and Xcode versions


But even the library is now created by MAC OS 10.15.4 and Xcode 11.4, the error message is the same:

"Building for ios Simultor but the linked library 'libf2c.a' was build for mac OS + ios


If you want, then I can ship You all the c-files and the makefile, to that you can reproduce the creation of the library.


What shold be the solution to create a library running in Xcode 11.4 , both in Simulator and on device, same as before ?

You adviced to do it in a xcode project, but How can I do all the works inside a xcode project or from a swift package, when I have native C-code ? In my Xcode project, i just inserted the library and it was working. But no more in Xcode 11.4

To create a static library for iOS in Xcode, start from the Static Library template when you create the project, and add all of the sources and headers to the project. To then get that project built as part of the app's build, you need to add it to set it up as a target dependency as described in TN2435. That document is focused on frameworks, but the process for static libraries is the same, except that the last step where you embed the framework in the app's build doesn't apply.


If you prefer to use a Swift Pacakge, which won't require an Xcode project file, we have an entire comprehensive section of the documentation devoted to them, so please start there.

It is often simply not possible to get the library from a third-party vendor fixed. We don't call the library code on simulator, but prior to Xcode 11.4 we at least could build and run everything else. Now we can't do that. We need to be able to link libraries and frameworks on a per-destination basis.

Have done your advice with the template for static library. It works !

I created 2 librarys, because I had the cources. One was for simulator and the other for device.

Then I put both together by lipo command and I use it for my App.

Now it is running on simulator and device as before.

Previous library had a size of 250 KB, but the new generated library 1.4 MB.

Both librarys are architecture: x86_64, arm64

Was it entirely necessary to (in my opinion) unceremoniously break the library/framework solution that has been employed by 3rd party, iOS SDK developers for over a decade? I realize that XCFramework has been a topic of discussion since mid-2019 and a feature in Xcode 11 since fall-2019, but to effectively decommission a solution that has functioned well for many years (given the lack of integrated support for external SDK distribution in the Apple dev tools) in a "minor" Xcode release (i.e. functional in 11.3, broken in 11.4) seems rash.


I recognize that the scripts and instructions provided to customers can be updated back into a functional state. I understand that when developer tools are updated a certain amount of risk is inherently accepted (which is why I do so infrequently and judiciously). Furthermore, I must admit excitement over an Apple-blessed solution to the SDK/framework distribution problem. However, my excitement is (which, technically, has now become "was") in regards to a potential, likely future when XCFramework adoption felt prudent and solid. For now, the present has been unceremoniously disrupted by perplexed customers that are using Xcode 11.4.

If everything is set up correctly, you won't need to use lipo directly. It sounds like you want your static library to be pre-compiled, which is fine, but you should create an XCFramework with the static library so that device and simulator are separate binaries. Combining Intel and ARM code in a single binary file isn't a correct and supported configuration.