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 
using
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

  http://www.lemoda.net/c/write-png/

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 
`_pei386_runtime_relocator'
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
c:/progs/mingw/bin/../lib/gcc/mingw32/4.6.2/libgcc.a(__main.o):(.text+0x52): 
undefined reference to `atexit'
c:/progs/mingw/bin/../lib/gcc/mingw32/4.6.2/libgcc.a(__main.o):(.text+0xb6): 
undefined reference to `atexit'
collect2: ld returned 1 exit status

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

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 
code:

cat >hello.c <<EOD
#include <stdlib.h>
#include <stdio.h>
int main(void){
   printf("Hello\n");
   exit(EXIT_SUCCESS);
}
EOD

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


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