iPhone library: file is not of required architecture

泄露秘密 提交于 2019-12-02 06:12:58

问题


I have searched for hours however I still have no clue what is wrong with my configuration. My project uses a self-written libray (myLib). This library is compiled to work only for simulator and it works perfectly there.

What do have to change so it compiles for my iPhone Device as well?

This is my current warning:

ld: warning: in /.../myLib.a, file is not of required architecture

This is my configuration (of myLib.a)

I found a lot of articles explaining the reason for this error however I could not find a solution:

The simulator runs on an x86 architecture, while the device uses an ARM architecture.


What do I have to change to get my library working on my iPhone?

Thanks


Edit:

What I did so far:

  1. Cleaned both projects
  2. Set library to 'Device' (3.1)
  3. Built the library
  4. Dragged the .a file of my library into my application

Result:

This works in simulator but setting the active sdk to device still raises a file is not of required architecture error.

I also tried mahboudz ( thanks for your support) link. It explains howto built the project using a shell script. However XCode keeps complaining that the library file is of the wrong architecture and the build fails.

This has to be a really stupid beginners mistake.


回答1:


You need to add both .a files,the one built for the device (build/$config-iphoneos)and the one built for the sim (build/$config-iphonesimulator) to the new project. Make sure you name them differently before dropping them in. This is how admob and similar offering ship their static libs.




回答2:


You need to compile your library for Intel so the Simulator can use it (which I gather you have done already), and then compile it for ARM, so it can run on the iPhone. Then you have to merge the two libraries. There are different ways to accomplish that, or make it more automatic.

Here are some links to help you:

http://blog.stormyprods.com/2008/11/using-static-libraries-with-iphone-sdk.html http://www.clintharris.net/2009/iphone-app-shared-libraries/




回答3:


I've met the same problem too. But seems you don't need to drag two .a files into the app project to solve this problem. This is what I did:

  1. Drag the static library project into app project's framework group
  2. "Get Info" for the target in app project
  3. Set the direct dependency of static library
  4. Make clean all unnecessary builds(for example the simulator build) in the static library project
  5. Build in the app project


来源:https://stackoverflow.com/questions/1542880/iphone-library-file-is-not-of-required-architecture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!