iPhone 模拟器:“libpng.dylib,文件不符合所需架构”
我试图将 libpng 库链接到我的 iphone 应用程序,并收到此错误:
ld: warning: in /opt/local/lib/libpng.dylib, file is not of required architecture
当我为模拟器或设备构建时会发生这种情况。
然而,当我构建控制台应用程序时,我可以很好地链接到 libpng 。
我做错了什么?我需要使用不同的 libpng.dylib 来进行 iPhone 开发吗?
I'm trying to link the libpng library to my iphone application, and getting this error:
ld: warning: in /opt/local/lib/libpng.dylib, file is not of required architecture
This happens when I build for the simulator or the device.
When I build a console application however, I can link in libpng just fine.
What am I doing wrong? Is there a different libpng.dylib I need to use for iphone development?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不能在 iPhone 上使用 dylibs,你需要静态编译它。话虽如此,您看到的错误是单独的问题。
您正在 Snow Leopard 上进行开发吗?如果是这样,那么您构建的默认库可能是 64 位的。模拟器需要 32 位库。您可以通过运行文件来检查它:
如果您没有看到类似的内容:
那么您将无法重用它。将库重新构建为静态 i386 库,您应该能够在模拟器中使用它。如果它是基于 autoconf 的构建这篇博客文章解释了如何进行构建并具有 shell 脚本您可以使用。
You can't use dylibs on iPhone, you will need to compile it statically. Having said that, the error you are seeing is separate issue.
Are you developing on Snow Leopard? If so then then the default library you built is likely 64 bit. The simulator requires 32 bit libraries. You can check by running file against it:
If you don't see something like:
Then you won't be able to reuse it. Rebuild the library as a static i386 lib and you should be able to use it in the simulator. If it is an autoconf based build this blog post explains how to do a build and has shell script that you can use.
正如 Chris Long 所说,libpng 在 iPhone 上不可用。您可以将其编译到您的项目中(如果它可以为 ARM 编译),否则它将无法工作。
这是一个线索: http:// www.cloudgoessocial.net/2009/06/09/imagemagick-on-iphone-with-jpeg-png/
另外,为了记录,您可以使用以下方法将 UIImage 写为 png:
UIImagePNGRepresentation( UIImage *图像)
As Chris Long says, libpng is not available on the iphone. You can compile it into your project (if it will compile for ARM), otherwise it no workums.
Here is a lead: http://www.cloudgoessocial.net/2009/06/09/imagemagick-on-iphone-with-jpeg-png/
Also, for the record, you can write out a UIImage as png natively using:
UIImagePNGRepresentation(UIImage *image)
这是你从网上下载的libpng.dylib吗? iPhone 开发人员不得使用外部动态库。
我不知道 libpng 是否可用,但以下是检查方法。
如果它不存在,则无法使用它。尝试找到一个静态库并从源代码编译它。它必须专门针对 iPhone 模拟器 (Intel) 和 iPhone (ARM) 的架构进行编译。
Is this a libpng.dylib you downloaded from the Internet? iPhone developers aren't allowed to use outside dynamic libraries.
I don't know if libpng is available, but here's how to check.
If it's not there, you can't use it. Try finding a static library and compile it from source. It has to be compiled specifically for both the architecture of the iPhone Simulator (Intel) and iPhone (ARM).