[英]Linker error with libpng under MacOSX
我正在研究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"
我知道libpng
基於zlib
,因此我在“其他鏈接器標志”中包含了-lz
但沒有任何改變。
有關如何使其工作的任何建議?
我用手動安裝libpng
解決了:
在終端中,進入下載的文件夾並啟動
cp ./scripts/makefile.darwin makefile make sudo make install make clean
如果它不起作用(在我的情況下)用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
這就是訣竅。 現在它工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.