Web lists-archives.com

Re: [Mingw-users] Using mingw's libpng?




On 02-Jul-2016 00:45, Eli Zaretskii wrote:
>> Date: Fri, 01 Jul 2016 18:13:23 -0700
>> From: mathog <mathog@xxxxxxxxxxx>
>> 
>> Are there some special command line switches needed to build a program
>> with the libpng dll in mingw?
> 
> That should be stated in the pkg-config file that comes with the
> libpng distribution you are using.

It is.  I meant in addition to that, because that set produced a binary 
that failed as described.  The config file's contents (the part that 
matters) are:

version="1.6.22"
prefix="/c/progs/mingw"
exec_prefix="${prefix}"
libdir="${exec_prefix}/lib"
includedir="${prefix}/include/libpng16"
libs="-lpng16"
all_libs="-lpng16 -lz "
I_opts="-I${includedir}"
L_opts="-L${libdir}"
R_opts=""
cppflags=""
ccopts=""
ldopts=""


> 
>> Using this test program:
>> 
>>    http://zarb.org/~gc/resource/libpng-short-example.c
>> 
>> on a Centos box:
>> 
>> gcc -o png-test libpng-short-example.c -lpng -lz -lm
>> ./png-test testcase.png foo.png
>> 
>> and the program ran.  It dumps the data pixel by pixel and copies the
>> image
>> from the first to the 2nd file.
>> 
>> However on Mingw with the same compile line and input data it does:
>> 
>> $ ./png-test testcase.png killme.png
>> 
>> This application has requested the Runtime to terminate it in an 
>> unusual
>> way.
>> Please contact the application's support team for more information.
>> libpng error: invalid after png_start_read_image or 
>> png_read_update_info
>> [read_png_file] Error during read_image
> 
> Before you make any conclusions, please try this build of libpng:
> 
> 
> https://sourceforge.net/projects/ezwinports/files/libpng-1.6.12-w32-bin.zip/download

Exactly the same.
> 
> The switches required to compile and link against the library are
> specified in the file lib/pkgconfig/libpng.pc included with this
> build, and all the dependency DLLs are also included.

It also fails with a brand new libpng build.
1.  get source, expand, CD to that directory

All the rest are in an MSYS window:

2.  ./configure
     ./make
     ./make install
3.   gcc -o png-test libpng-short-example.c 
-I/usr/local/include/libpng16 -lpng16 -lz -lm -L/usr/local/bin
4.  Hide the libpng that was already present by
mv /c/progs/mingw/bin/libpng16.dll 
/c/progs/mingw/bin/__HIDE_libpng16.dll

5. ./png-test testcase.png foo.png

This application has requested the Runtime to terminate it in an unusual 
way.
Please contact the application's support team for more information.
libpng error: invalid after png_start_read_image or png_read_update_info
[read_png_file] Error during read_image

Dependency walker shows that DOS/Windows cannot find libpng16.dll, since 
that is
tucked away in a location that only MSYS knows about (MSYS's path is:

PATH='.:/usr/local/bin:/mingw/bin:/bin:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/mingw/bin'
)

The DOS path is:

Path=C:\Windows\system32;C:\Windows;C:\progs\mingw\bin

and it fails the same way when run from DOS (after the libpng16.dll from 
/usr/local/bin is copied to the same directory as png-test.

The programs that were built by the libpng make all seem to work - and 
dependency walker doesn't show any of them linked to the DLL.  Looking 
at the log of the build one finds:

gcc -DHAVE_CONFIG_H -I.     -I/usr/local/include -MT pngtest.o -MD -MP 
-MF $depbase.Tpo -c -o pngtest.o pngtest.c &&\
/bin/sh ./libtool  --tag=CC   --mode=link gcc  -I/usr/local/include  
-L/usr/local/lib -o pngtest.exe pngtest.o libpng16.la -lz

and

libtool: link: gcc -I/usr/local/include -o .libs/pngtest.exe pngtest.o  
-L/usr/local/lib ./.libs/libpng16.dll.a -lz -L/usr/local/lib

Dependency walker shows the final one as having a link to libpng16.dll, 
and this version works if run from the top directory like:

.libs/pngtest

The copy of libpng16.dll it is using (according to dependency walker, 
probably MSYS does things differently) is the one in .libs, not the one 
in /usr/local/lib.

So, build pngtest.c (from libpng) using the simplest possible command 
line:

cd .libs
  gcc -o /c/temp/pngtest pngtest.c  -lpng16 -lz -lm
cp pngtest.png /c/temp
cd /c/temp
./pngtest

and it runs normally.  It should not have.  The dll it is supposedly 
using from /ming/bin is still hidden.  Hide the one in /usr/local/bin 
too and then pngtest fails.  UnHide (remove the __HIDE_) from the one in 
/mingw/bin and pngtest works again.

So great, we have one set of programs which work exactly like they do 
under linux (the test programs that come with libpng) and another set 
that blow up mysteriously when linked to this library (the small test 
program from my original post and the module from a much bigger package 
which triggered this line of inquiry.)

Perhaps this is some version incompatibility between the code in the 
ones that do not work and the current libpng?  Check back on the Linux 
systems I used, the one for the build of the larger package, and the one 
for the smaller test program, are both using libpng1.2.  Could be that 
all I need to get the problem ones to work is to install that older 
version (too).

Regards,

David Mathog
mathog@xxxxxxxxxxx
Manager, Sequence Analysis Facility, Biology Division, Caltech

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe