我正在研究MacOSX 10.7.2和Xcode 4.2.1。我使用port安装了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"
我知道libpng
基于zlib
,因此我在“其他链接器标记”中包含了-lz
但没有任何更改。
有关如何使其发挥作用的任何建议吗?
答案 0 :(得分:5)
我解决了手动安装libpng
:
,进入下载的文件夹并启动
cp ./scripts/makefile.darwin makefile
make
sudo make install
make clean
如果它不起作用(在我的情况下)用TextEdit(或等效的)打开makefile
并更改行
ARCH="-arch i386 -arch x86_64"
in
ARCH=-arch x86_64
(假设您的系统当然是64位)。
这可能还不够。 Xcode仍无法找到该库。我解决了使用
cd /usr/local/lib
sudo ln -s libpng15.dylib ./libpng15.15.dylib
这就是诀窍。现在它工作正常。