MacOSX下与libpng的链接器错误

Man*_*lio 7 macos xcode linker-errors libpng

我正在研究MacOSX 10.7.2和Xcode 4.2.1.我libpng使用端口安装,我试图在我的应用程序中加载PNG图像,但我得到链接器错误:

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
Run Code Online (Sandbox Code Playgroud)

png.h在项目中使用了

#include "/usr/X11/include/png.h"
Run Code Online (Sandbox Code Playgroud)

我知道libpng是基于zlib,因此我已经包含-lz在"其他链接器标志"中,但没有任何改变.

有关如何使其工作的任何建议?

Man*_*lio 5

我用手动安装解决了libpng:

  • 官方网站下载源代码
  • 在终端中,进入下载的文件夹并启动

    cp ./scripts/makefile.darwin makefile
    make 
    sudo make install
    make clean
    
    Run Code Online (Sandbox Code Playgroud)
  • 如果它不起作用(在我的情况下)makefile用TextEdit(或等效的)打开并更改行

    ARCH="-arch i386 -arch x86_64"

    ARCH=-arch x86_64

    (假设,当然,您的系统是64位).

这可能还不够.Xcode仍无法找到该库.我解决了使用

cd /usr/local/lib
sudo ln -s libpng15.dylib ./libpng15.15.dylib
Run Code Online (Sandbox Code Playgroud)

这就是诀窍.现在它工作正常.