Linker error with libpng on MacOSX

I am working on MacOSX 10.7.2 and Xcode 4.2.1. I installed libpng using the port and I tried to load the 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 that libpng based on zlib , so I included -lz in the "Other linker flags", but nothing has changed.

Any suggestions on how to make it work?

+6
source share
1 answer

I decided with manual installation of libpng :

  • Download source from official website
  • in the terminal, go to the downloaded folder and run

     cp ./scripts/makefile.darwin makefile make sudo make install make clean 
  • if it does not work (as in my case), open the makefile using TextEdit (or equivalent) and change the line

    ARCH="-arch i386 -arch x86_64"

    in

    ARCH=-arch x86_64

    (unless, of course, your system is 64 bit).

This may not be enough. Xcode still could not find the library. I decided to use

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

This is a trick. Now it works great.

+5
source

Source: https://habr.com/ru/post/908839/


All Articles