MacOSX 下 libpng 的链接器错误

发布于 2025-01-07 01:50:18 字数 1692 浏览 0 评论 0原文

我正在使用 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

在我的项目中包含了 png.h

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

我使用I Know < code>libpng 基于 zlib,因此我已将 -lz 包含在“其他链接器标志”中,但没有任何更改。

关于如何使其发挥作用有什么建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热血少△年 2025-01-14 01:50:18

我通过手动安装 libpng 解决了问题:

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

    cp ./scripts/makefile.darwin makefile
    制作 
    须藤进行安装
    使干净
    
  • 如果它不起作用(如我的情况),请使用 TextEdit (或等效工具)打开 makefile 并更改线

    ARCH="-arch i386 -arch x86_64"

    ARCH=-arch x86_64

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

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

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

它解决了这个问题。现在效果很好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文