问题描述
我正在使用MacOSX 10.7.2和Xcode 4.2.1.我使用端口安装了libpng
,试图在应用程序中加载PNG图像,但出现链接器错误:
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
我使用
#include "/usr/X11/include/png.h"
我知道libpng
是基于zlib
的,因此我已将-lz
包含在其他链接器标志"中,但没有任何更改.
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?
推荐答案
我通过手动安装libpng
解决了问题:
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
如果它不起作用(如我的情况),请使用TextEdit(或同等功能)打开makefile
并更改行
if it doesn't work (as in my case) open makefile
with TextEdit (or equivalent) and change line
ARCH="-arch i386 -arch x86_64"
在
ARCH=-arch x86_64
(当然,假设您的系统是64位).
(assuming, of course, your system is 64 bit).
可能还不够. Xcode仍然找不到该库.我解决了使用
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.
这篇关于MacOSX下libpng的链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!