Web lists-archives.com

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

On 06-Jul-2016 15:58, Paul Moore wrote:
> If you are very, very, careful, you can build Python extensions with
> mingw, but you have to take care not to pass CRT data (such as FILE
> pointers) across the DLL boundaries. Clearly this care isn't being
> taken here. Probably because libpng doesn't expose a "safe" API that
> uses a filename rather than a FILE*. So the extension author probably
> had little choice. The decision is reasonable, as mixing compilers
> isn't supported anyway, as you've found out.

In theory it should be possible to build these extensions with mingw 
something like:

   gcc hello.c -nostdlib -lmsvcr90 -lgcc -o hello.exe

In practice with a few minutes futzing around along those lines I did 
not stumble upon a combination of flags which would work for a test case 
which is the code from here


saved as "fruit.c" and then compiled like:

$ gcc  -Wall -o killme fruit.c   -I/c/progs/mingw/include/libpng16 
-L/c/progs/mingw/libs -lpng16 -lz -lm

works and the program produced runs and works OK.  However...

$ gcc  -Wall -o killme fruit.c   -I/c/progs/mingw/include/libpng16 
-L/usr/local/libs -lpng16 -lz -lm -nostdlib -lgcc  -lmsvcr90
ertr000001.o:(.rdata+0x0): undefined reference to 
collect2: ld returned 1 exit status

$ gcc  -Wall -o killme fruit.c   -I/c/progs/mingw/include/libpng16 
-L/usr/local/libs -lpng16 -lz -lm -nostdlib -lmsvcr90 -lgcc
undefined reference to `atexit'
undefined reference to `atexit'
collect2: ld returned 1 exit status

moving the last 3 "-l" parameters forward, before -png16 didn't help 

Admittedly the libpng it is trying to link to was built with msvcrt.dll, 
so possibly it is missing one of these pieces, but adding -lmsvcrt onto 
the end
didn't resolve either error message.  Perhaps it would work if the whole 
libpng was built first with those flags.

I really doubt it though, because when tested with the simplest possible 

cat >hello.c <<EOD
#include <stdlib.h>
#include <stdio.h>
int main(void){

These gave the same errors as above:
gcc -Wall -o killme hello.c  -nostdlib -lgcc  -lmsvcr90
gcc -Wall -o killme hello.c  -nostdlib  -lmsvcr90 -lgcc


David Mathog
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.
MinGW-users mailing list

This list observes the Etiquette found at 
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:
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe