Question

I am getting this error for one of my project to use a static library. The project runs well in iOS device. But not in simulator. The static library is not mine, so I cannot recompile it for i386. But this is a hardware driver, for iPhone. So when running in Simulator I really do not need this library. Its like if the Accessory is present with the device then the app will have a different flow.

So I have to keep the reference to this file. But will only need in iOS device. Not needed when running in the simulator to run the app for UI and other testing purpose.

How can I avoid this error? Is there anyway to configure the target or scheme to avoid the object file/lib when running in simulator?

ld: warning: ignoring file 
/Framework/iSmartSDK/libiSmartSDK_Lib.a, missing required architecture i386 in file  
/Framework/iSmartSDK/libiSmartSDK_Lib.a (2 slices)
Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_iSmart", referenced from:
      objc-class-ref in SmartCardReaderVC.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Was it helpful?

Solution

when you use it, the symbol IS referenced and the lib required. if you really dont need the the functionality, wrap its usage in a define. 'define it out':

#if TARGET_OS_IPHONE
   iSmart *smart = ....
#else
   NSLog(@"no ismart on mac");
#endif

NOTE: It's not enough to not assign/call a symbol. dont even use the symbol for declaring a variable**


It might only be in the 1 file AFAICS .. #ifdef the whole file and maybe create a SmartReaderVC stub

OTHER TIPS

Even though you say you don't need the library in the emulator, the linker says something else. It's looking for the class iSmart.

The best way forward is probably to write a stub for the class iSmart:

  • Create a static library project.

  • Add a very, very minimal class iSmart, e.g. the class and two methods. Each method does either nothing or return 0.

  • Build the library for the emulator (i386).

  • Use the lipo tool to merge the library from the third-party and the i386 part of your stub library into a single library (resulting in large part for the device and a very minimal part for the emulator).

  • Link your app with the custom built library instead of the original one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top