0

For the below program compiling with GCC works:

$ gcc memtray.c `pkg-config --libs --cflags gtk+-2.0`

But not with TinyC (the command is different in a single character g->t):

$ tcc memtray.c `pkg-config --libs --cflags gtk+-2.0`
tcc: error: undefined symbol 'main'

But main is there:

#include <gtk/gtk.h>
#include <string.h>
#include <stdlib.h>

..... program code .....    

int main(int argc, char ** argv) {
    gtk_init(&argc, &argv);
    create_tray_icon();
    gtk_main();
    return 0;
}

Here is what pkg-config unrolls to:

$ pkg-config --libs --cflags gtk+-2.0
-pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include
-I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0
-I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1
-I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12
-I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
-I/usr/include/freetype2 -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0
-latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0
-lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype

Notice the -phtread part, it is not really necessary for my program, if I issue the command below (same as above but without without -pthread), compilation works:

 $ tcc memtray.c -o memtray -I/usr/include/gtk-2.0
-I/usr/lib/x86_64-linux-gnu/gtk-2.0/include
-I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0
-I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1
-I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12
-I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
-I/usr/include/freetype2 -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0
-latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0
-lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype

But such long command is not only inconvenient but also is less portrable.

How to compile GTK2 program with TinyC and pkg-config?

liberforce
  • 11,189
  • 37
  • 48
exebook
  • 32,014
  • 33
  • 141
  • 226
  • FWIW I can't reproduce this with tcc 0.9.27: a minimal example compiles fine – Jussi Kukkonen Apr 22 '18 at 16:30
  • 2
    This sounds like a bug in `tcc`'s handling of the `-pthread` switch. As a workaround, you could remoe `-pthread` using `pkg-config --libs --cflags gtk+-2.0 | sed -e 's/-pthread//'` – user4815162342 Apr 22 '18 at 16:52

0 Answers0