Search code examples
cgccpango

linking error. Perhaps a problem with ordering?


I'm building a program which uses GTK+3 and pango. Most of it compiles fine apart from the last bit which builds the executable. The final command is:

gcc -o z80sim main.c -Wall -Iz80 -Igui obj/disas.o obj/iosim.o obj/sim0.o obj/sim1.o obj/sim2.o obj/sim3.o obj/sim4.o obj/sim5.o obj/sim6.o obj/sim7.o obj/simctl.o obj/simfun.o obj/simglb.o obj/simint.o obj/callbacks.o obj/code.o obj/guiglb.o obj/memory.o obj/flags.o obj/log.o obj/ports.o obj/registers.o `pkg-config --cflags --libs gtk+-3.0`

But I get this error message:

obj/sim1.o: In function `cpu':
sim1.c:(.text+0x2cb): undefined reference to `check_gui_break'
obj/callbacks.o: In function `on_open1_activate':
callbacks.c:(.text+0x20): undefined reference to `Get_File'
:
:

Where check_gui_break is defined and called in sim1.c etc.

This has to be something to do with the ordering of object files and libraries on the ld call, but I have tried putting the pkg-config part before and after the individual .o files and it still gives the same errors.

I've read the very informative https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking but, although I know a lot more now, I still can't crack this one.

BTW.

pkg-config --cflags --libs gtk+-3.0

gives

-pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0

Please will some kind soul take pity on me and enlighten me?


Solution

  • It appears that most of the errors I've encountered have been a result of the transition from Glade2 to Glade3. In 2, Glade generates some C code which is what's missing from my code. Back to the reference manual to see how to modernise the code.