Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

iphone - How to get rid of the warning "file was built for unsupported file format" when linking with a static library?

I've an application which includes an external library I developed, and I'm getting the following warning message every time I compile using the device as target:

mylib-release-iphonesimulator.a, file was built for unsupported file format which is not the architecture being linked (armv7).

I've 2 versions of the library, both added into the project. One built for the iphonesimulator and the other for iphoneos.

Even though it works well on any target (seems the compiler takes the correct version of the library depending of the target) that sort of warning becomes anoying.

Is any way to get rid of the warning, or even better compile both platforms on a single library avoiding to have 2 binaries of the same library?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't want to get rid of this error, you want to fix it.

The problem here is that you're linking a simulator version of your library into the device build of your app. The simulator wants libraries in the i386 architecture, and the device wants things in the armv6 or armv7 architecture.

So the solution here is to link the correct version of your library.

What I usually do is combine them into a single library and let the linker pick the right version for me. Here's what you do in Terminal:

$ cd /path/to/my/libraries
$ ls 
  libMyLibrary-Device.a
  libMyLibrary-Simulator.a
$ file libMyLibrary-Device.a
  libMyLibrary-Device.a: Mach-O universal binary with 2 architectures
  libMyLibrary-Device.a (for architecture armv6):   current ar archive random library
  libMyLibrary-Device.a (for architecture armv7):   current ar archive random library
$ file libMyLibrary-Simulator.a
  libMyLibrary-Simulator.a: Mach-O universal binary with 1 architecture
  libMyLibrary-Simulator.a (for architecture i386): current ar archive random library
$ lipo -create -output libMyLibrary.a libMyLibrary-Device.a libMyLibrary-Simulator.a
$ ls
  libMyLibrary-Device.a
  libMyLibrary-Simulator.a
  libMyLibrary.a
$ file libMyLibrary.a
  libMyLibrary.a: Mach-O universal binary with 3 architectures
  libMyLibrary.a (for architecture armv6):  current ar archive random library
  libMyLibrary.a (for architecture armv7):  current ar archive random library
  libMyLibrary.a (for architecture i386):   current ar archive random library

Then you just link libMyLibrary instead of the device or simulator version, and the linker will do the right thing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...