I am using MinGW/MSYS on Windows XP.
I cannot build the example program at contrib/examples/pngtopng.c because of linker errors:
$ gcc --version
gcc.exe (tdm64-1) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ pwd
/home/A/libpng-1.6.21/contrib/examples
$ md5sum pngtopng.c
6543e180dd99dc4832b5e0386d68e995 *pngtopng.c
$ gcc -m32 pngtopng.c -o pngtopng.exe
C:\DOCUME~1\A\LOCALS~1\Temp\ccc91WIy.o:pngtopng.c:(.text+0x5e): undefined reference to `png_image_begin_read_from_file'
C:\DOCUME~1\A\LOCALS~1\Temp\ccc91WIy.o:pngtopng.c:(.text+0x106): undefined reference to `png_image_finish_read'
C:\DOCUME~1\A\LOCALS~1\Temp\ccc91WIy.o:pngtopng.c:(.text+0x149): undefined reference to `png_image_write_to_file'
C:\DOCUME~1\A\LOCALS~1\Temp\ccc91WIy.o:pngtopng.c:(.text+0x1da): undefined reference to `png_image_free'
collect2.exe: error: ld returned 1 exit status
In advance of building libpng, the zlib 1.2.8 library was successfully built and installed.
The PNG library was successfully built and installed with the following commands:
$ cd libpng-1.6.21/
$ ./configure \
> CFLAGS="-march=native -mtune=native -Ofast -m32" \
> CPPFLAGS="-I/local/include" \
> LDFLAGS="-L/local/lib"
$ make
$ make install-strip
My Questions, ordered by decreasing importance:
Your build command for pngtopng.exe needs to include appropriate -I and -L options so gcc can find libpng, and "-lpng -lz" options as well.
Adding the above options does not work, as shown below.
I believe the problem has to do with the Simplified API being skipped for compilation due to bad configuration or bad macros. I wish to see your own commands for building the library and the pngtopng program.
glenn.rp> ./configure --prefix=$HOME
glenn.rp> make
glenn.rp> make install
glenn.rp> cd contrib/examples
glenn.rp> gcc -L/$HOME/lib -I/$HOME/include -o pngtopng pngtopng.c -lpng16 -lz
glenn.rp> ./pngtopng ../../pngtest.png pngout.png
glenn.rp> ls -l pngout.png
-rw-rw-r-- 1 glennrp glennrp 6504 Apr 12 17:46 pngout.png
glenn.rp> ldd pngtopng
linux-vdso.so.1 => (0x00007fff29bf9000)
libpng16.so.16 => /home/glennrp/lib/libpng16.so.16 (0x00007fc133fec000)
libc.so.6 => /lib/x8664-linux-gnu/libc.so.6 (0x00007fc133c27000)
libz.so.1 => /home/glennrp/lib/libz.so.1 (0x00007fc133a10000)
libm.so.6 => /lib/x8664-linux-gnu/libm.so.6 (0x00007fc13370a000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc13421e000)
Note that the "-lpng16 -lz" (or "-lpng -lz") have to come at the end of the gcc command, or at any rate, after "pngtopng.c".
Last edit: Glenn Randers-Pehrson 2016-04-12
Thank you for your assistance.
Indeed the problem was caused by the bad placement of
-lpngin the build command.This behavior is deserving of at least a warning message from GCC, but that's off-topic.