Linker error with libpng under MacOSX

倖福魔咒の 提交于 2020-01-01 09:28:44

问题


I'm working on MacOSX 10.7.2 and Xcode 4.2.1. I installed libpng using port and I was trying to load a PNG image in my application, but I get linker errors:

Undefined symbols for architecture x86_64:
  "_png_create_read_struct", referenced from:
      loadPngImage(char*, int&, int&, bool&, unsigned char**) in test.o
  "_png_create_info_struct", referenced from:
      loadPngImage(char*, int&, int&, bool&, unsigned char**) in test.o
  "_png_destroy_read_struct", referenced from:
      loadPngImage(char*, int&, int&, bool&, unsigned char**) in test.o
  "_png_set_longjmp_fn", referenced from:
      loadPngImage(char*, int&, int&, bool&, unsigned char**) in test.o
  "_png_init_io", referenced from:
      loadPngImage(char*, int&, int&, bool&, unsigned char**) in test.o
  "_png_set_sig_bytes", referenced from:
      loadPngImage(char*, int&, int&, bool&, unsigned char**) in test.o
  "_png_read_png", referenced from:
      loadPngImage(char*, int&, int&, bool&, unsigned char**) in test.o
  "_png_get_IHDR", referenced from:
      loadPngImage(char*, int&, int&, bool&, unsigned char**) in test.o
  "_png_get_rowbytes", referenced from:
      loadPngImage(char*, int&, int&, bool&, unsigned char**) in test.o
  "_png_get_rows", referenced from:
      loadPngImage(char*, int&, int&, bool&, unsigned char**) in test.o
ld: symbol(s) not found for architecture x86_64

I included png.h in my project using

#include "/usr/X11/include/png.h"

I know libpng is based on zlib, thus I have included -lz in "Other linker flags" but nothing changed.

Any suggestions on how to make it work?


回答1:


I solved with a manual installation of libpng:

  • download the source from official web site
  • in Terminal, go in the downloaded folder and launch

    cp ./scripts/makefile.darwin makefile
    make 
    sudo make install
    make clean
    
  • if it doesn't work (as in my case) open makefile with TextEdit (or equivalent) and change line

    ARCH="-arch i386 -arch x86_64"

    in

    ARCH=-arch x86_64

    (assuming, of course, your system is 64 bit).

It may not be enough. Xcode was still unable to find the library. I solved using

cd /usr/local/lib
sudo ln -s libpng15.dylib ./libpng15.15.dylib

That did the trick. Now it works fine.



来源:https://stackoverflow.com/questions/9351777/linker-error-with-libpng-under-macosx

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