Is it possible to use a static library only when testing with a device, not a simulator?

I have an external closed library that can only be compiled with armv7s (etc.). when I try to compile against the simulator, it is obvious that it does not work and displays some errors. I do not want to embed this library in my code if I cannot configure Xcode to use this library only when checking with the device. unfortunately, I tried to do this with cocoapods without success, and I wonder if there is a way to do this?

+6
source share
2 answers

Yes, it can be done. I had a similar issue with a framework that caused linker errors only in the simulator, so I set up my project to use the framework when creating for the device.

The following assumes that you are not using cocoa pods to link the library. I'm not sure what will need to change if you.

  • Select your goal and go to the Build Phases tab.
  • In the Linking Binaries to Libraries section, remove the static library from the list.
  • Click on the "Build Settings" tab.
  • Find "Other linker flags."
  • Double-click the Debug value. Tap the + button and enter -smlelibrary
  • Instead of "somelibrary", enter the actual name of your library minus the leading "lib". Do not enable the extension.
  • Select the value "Debug" and notice the small circle +. Click +.
  • Click on the new "Any architecture | Any SDK" part and change it to "Any IOS Simulator SDK".
  • Now double-click the value to the right of the β€œAny IOS Simulator SDK” and delete the added -somologibrary entry.

Now build the debug assembly.

The above change basically means that the library is bundled in all builds except iOS Simulator.

You may also need to make some changes to the code. Any code that references header files or other characters from the library should be wrapped as follows:

#if !TARGET_IPHONE_SIMULATOR #import "somelibrary.h" #endif #if !TARGET_IPHONE_SIMULATOR // Use stuff from the library #endif 
+11
source

The reason is that the library is missing a slice of the i386 architecture (simulator), and not a problem ...

Now that you use the target library "Sim" ... and all codes associated with it will be excluded.

When you use the target device "Device" ... the code and library will be included

0
source

Source: https://habr.com/ru/post/977135/


All Articles