1

I'm trying to cross-compile on Linux (i686-w64-mingw32-gcc) a small 32-bit Windows program that requires (libz, libpng and) libgd. I have them all installed correctly, as far as I can tell, though the linker keeps on complaining it can't locate the libgd functions I'm using.

$ i686-w64-mingw32-gcc -lgd -lpng -lz -lm -o demo demo.o smssc.o
demo.o:demo.c:(.text+0x2d): undefined reference to `_imp__gdImageCreateFromPng@4'
demo.o:demo.c:(.text+0x1f7): undefined reference to `_imp__gdImageGetPixel@12'
demo.o:demo.c:(.text+0x316): undefined reference to `_imp__gdImageCreate@8'
demo.o:demo.c:(.text+0x368): undefined reference to `_imp__gdImagePaletteCopy@8'
demo.o:demo.c:(.text+0x3b0): undefined reference to `_imp__gdImageGetPixel@12'
demo.o:demo.c:(.text+0x3ec): undefined reference to `_imp__gdImageSetPixel@16'
demo.o:demo.c:(.text+0x430): undefined reference to `_imp__gdImageDestroy@4'
demo.o:demo.c:(.text+0x465): undefined reference to `_imp__gdImageSetPixel@16'
demo.o:demo.c:(.text+0x4a9): undefined reference to `_imp__gdImageSetPixel@16'
demo.o:demo.c:(.text+0x4e0): undefined reference to `_imp__gdImageColorAllocate@16'
demo.o:demo.c:(.text+0x569): undefined reference to `_imp__gdImageLine@24'
demo.o:demo.c:(.text+0x5e9): undefined reference to `_imp__gdImageLine@24'
demo.o:demo.c:(.text+0x669): undefined reference to `_imp__gdImageLine@24'
demo.o:demo.c:(.text+0x6e3): undefined reference to `_imp__gdImageLine@24'
demo.o:demo.c:(.text+0x70f): undefined reference to `_imp__gdImagePng@8'
demo.o:demo.c:(.text+0x71f): undefined reference to `_imp__gdImageDestroy@4'

this is how I had configured libgd

./configure --host=i686-w64-mingw32 --prefix=/usr/i686-w64-mingw32 CPPFLAGS="-I/usr/i686-w64-mingw32/include" LDFLAGS="-L/usr/i686-w64-mingw32/lib"

of course libgd.a, libpng.a and libz.a are found into my /usr/i686-w64-mingw32/lib

also, objdump output seems correct:

$ objdump -tT /usr/i686-w64-mingw32/lib/libgd.a
In archive /usr/i686-w64-mingw32/lib/libgd.a:
gd.o:     file format pe-i386
[snip]
sverx
  • 67
  • 8
  • 2
    Probably related to wrong library order. See https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc – Andrew Henle Jun 26 '19 at 12:12
  • @AndrewHenle libgd uses libpng and libz so it should be first I guess. BTW it didn't work even putting that second or third or last. – sverx Jun 26 '19 at 12:17
  • 2
    The "right" order shown in that other question has your code at the start of the arguments, dependencies after it. You have the opposite. – Mat Jun 26 '19 at 12:26
  • @Mat Oh gosh. I wonder why on MinGW on Windows it worked. Putting libraries at the end seems to fix the linking problem. Thanks! – sverx Jun 26 '19 at 12:34

0 Answers0