xcode MacOSX 下 libpng 的链接器错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9351777/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:21:27  来源:igfitidea点击:

Linker error with libpng under MacOSX

xcodemacoslinker-errorslibpng

提问by Manlio

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

我正在使用 MacOSX 10.7.2 和 Xcode 4.2.1。我libpng使用 port安装,并且试图在我的应用程序中加载 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

I included png.hin my project using

我包括png.h在我的项目中使用

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

I know libpngis based on zlib, thus I have included -lzin "Other linker flags" but nothing changed.

我知道libpng基于zlib,因此我已将其包含-lz在“其他链接器标志”中,但没有任何改变。

Any suggestions on how to make it work?

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

采纳答案by Manlio

I solved with a manual installation of libpng:

我通过手动安装解决了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 makefilewith 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).

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

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

    ARCH="-arch i386 -arch x86_64"

    ARCH=-arch x86_64

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

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

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

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

That did the trick. Now it works fine.

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