0

A project I'm working on builds cairo from source, calling its ./configure and make. I'm using git-bash.exe from a PortableGit install, with environment variables from a different MinGW. So I have:

WORKGROUP+user@AD-X MINGW32 /z/user/Downloads/path/to/build/cairo (master)
$ which gcc
//WORKGROUP.EX.COM/Users/user/Downloads/mingw-w64/i686-4.9.3-posix-dwarf-rt_v4-rev1/mingw32/bin/gcc

WORKGROUP+user@AD-X MINGW32 /z/user/Downloads/path/to/build/cairo (master)
$ gcc --version | head -1
gcc.exe (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 4.9.3

The compilation goes fine, but linking goes bad here:

[...]
  CC     any2ppm-any2ppm.o
  CCLD   any2ppm.exe
C:\Users\TEMPCR~1.000\AppData\Local\Temp\45\ccaKwhAD.ltrans0.ltrans.o:<artificial>:(.text+0x71): undefined reference to `cairo_image_surface_create'
C:\Users\TEMPCR~1.000\AppData\Local\Temp\45\ccaKwhAD.ltrans0.ltrans.o:<artificial>:(.text+0x163): undefined reference to `cairo_image_surface_get_data'
[...]
makefile:483: recipe for target 'all' failed
make: *** [all] Error 2

 ^ Received error ^

Unfortunately, make V=1 does not work for this Makefile to reveal its commands, so I used a dry run make -n to get the CCLD any2ppm.exe command, which is:

echo "  CCLD  " any2ppm.exe;Z:/user/Downloads/PortableGit/usr/bin/sh.exe ../libtool --silent --tag=CC   --mode=link gcc     -Os -m32  -Wl,--allow-shlib-undefined -m32 -o any2ppm.exe any2ppm-any2ppm.o ../util/cairo-script/libcairo-script-interpreter.la ../src/libcairo.la      -lm

... and by removing the --silent switch from the ../libtool and re-running the command, the actual gcc command failing is (line split mine):

# runs in /z/user/Downloads/path/to/build/cairo/test
libtool: link: gcc \
-Os -m32 -Wl,--allow-shlib-undefined -m32 \
-o .libs/any2ppm.exe any2ppm-any2ppm.o \
../util/cairo-script/.libs/libcairo-script-interpreter.a \
Z:/user/Downloads/path/to/build/cairo/src/.libs/libcairo.a \
-LZ:/user/Downloads/path/to/build/_buildroot/lib ../src/.libs/libcairo.a \
/z/user/Downloads/path/to/build/_buildroot/lib/libpixman-1.a \
/z/user/Downloads/path/to/build/_buildroot/lib/libpng16.a \
-lgdi32 -lmsimg32 -lz -pthread

Here's the thing - the link error has "undefined reference tocairo_image_surface_get_data'`", but if I check:

WORKGROUP+user@AD-X MINGW32 /z/user/Downloads/path/to/build/cairo/test (master)
$ nm -a Z:/user/Downloads/path/to/build/cairo/src/.libs/libcairo.a  | grep cairo_image_surface_get_data
00000000 r .gnu.lto_cairo_image_surface_get_data.f85122d4

... there is some sort of a symbol, except prefixed with .gnu.lto_? I've found Sourceware Bugzilla: 13557 – Undef. ref. err. when linking with slim LTO obj. in static lib. (mingw32 target), but I guess that fix is already in the compiler I use (4.9.3)? I also tried reversing the order of the libraries included on the linking command line, that didn't work either.

So, in brief, in libcairo.a which is explicitly given with correct full path at the gcc command line (and statically linked), there is a .gnu.lto_cairo_image_surface_get_data.f85122d4, yet linking fails with "undefined reference to `cairo_image_surface_get_data'". Why does this happen, and how can I get the link command to succeed?

(Ironically, I have compiled cairo before in the same git-bash.exe on the same machine, but it was probably a different MinGW environment - cannot really recall)

sdaau
  • 36,975
  • 46
  • 198
  • 278

1 Answers1

0

Found this: undefined reference cross compiling static libraries with LTO under GCC

I'm able to reproduce this linking problem on Mingw32-gcc 4.9.2 under Win7 64-bit. However, I did get it to link successfully by adding -ffat-lto-objects as a workaround:

... and it worked for me, too...

Community
  • 1
  • 1
sdaau
  • 36,975
  • 46
  • 198
  • 278