Question

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?

Was it helpful?

Solution

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)

OTHER TIPS

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:

file /opt/local/lib/libpng.dylib

If you don't see something like:

(for architecture i386):    Mach-O dynamically linked shared library i386

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.

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.

  1. Double-click on your app name in the Targets list.
  2. Click the Plus button under the Frameworks list and try to find it. Don't forget that lowercase names appear after "Z".

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).

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