2

Trying to compile a C GTK gui + Prolog file using GPLC. I read that I can pass multiple flags to the gcc compiler from GPLC by using-C 'gcc flags here'

Ok so I can comiple my GUI alone with

gcc foo.c `pkg-config --cflags --libs gtk+-2.0` -o $(NAME)

However this will not work in GPLC because I would have

'`pkg-config --cflags --libs gtk+-2.0`'

This means I won't get the response from pkg-config as I am seeking because it is inside a "string". How can I fix that?

Lastly if I do something ugly like:

gplc -c foo1.c -C '-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'
gplc -c foo2.pl
gplc foo1.o foo2.o -o gyges

I get compilation failure during linking due to all references to GTK functions being undefined. why?

Zeth
  • 68
  • 6

2 Answers2

2

Use shell in a Makefile:

GTK_FLAGS = $(shell pkg-config --cflags --libs gtk+-2.0)
gplc -c foo1.c -C $(GTK_FLAGS)

EDIT:

CC = gplc
GTK_CFLAGS = $(shell pkg-config --cflags gtk+-2.0)
GTK_LIBS = $(shell pkg-config --libs gtk+-2.0)
OBJECTS = foo1.o foo2.o

all: gyges

foo1.o: foo1.c
    $(CC) -c foo1.c -o foo1.o $(GTK_CFLAGS)

foo2.o: foo2.pl
    $(CC) -c foo2.pl -o foo2.o

gyges: $(OBJECTS)
    $(CC) $(OBJECTS) -o gyges $(GTK_LIBS)
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
  • Thanks. This solves my first problem however I still cannot get it to link, I have tried adding the libs during linking in various order but gplc refuses to see them, gcc doesn't have this problem. – Zeth Nov 01 '15 at 08:11
  • You have an edit, I've never used GPLC, but see if this works – David Ranieri Nov 01 '15 at 08:20
  • 1
    That didn't work. But I discovered the problem reading through the gplc man. To pass options to the gcc compiler the `-C` flag is used and to pass to the linker the `-L` flag needs to be used!! That was my problem, so your make with -L during linking and -C while compiling the .c's makes it work. – Zeth Nov 01 '15 at 09:02
  • 1
    @Zeth: Then please, answer your own question! – false Nov 01 '15 at 12:34
1

Answer

To solve the first problem I just needed to use shell inside a Makefile as Alter Mann pointed out.

The second problem was occurring because GPLC was not seeing the gtk libs during linking. This is because I was using the -C flag to pass args to the gcc compiler during compilation AND linking, this is incorrect, the -L flag is the flag that must be used to pass args to gcc during linking according to the gplc man.

So my final working MAKE looks likes this:

CC = gplc
GTK_CFLAGS = $(shell pkg-config --cflags gtk+-2.0)
GTK_LIBS = $(shell pkg-config --libs gtk+-2.0)
OBJECTS = foo1.o foo2.o

all: name

foo1.o:
     $(CC) -c foo1.c -o foo1.o -C '$(GTK_CFLAGS)'

foo2.o:
    $(CC) -c foo2.pl -o foo2.o

name: $(OBJECTS)
    $(CC) $(OBJECTS) -o name -L '$(GTK_LIBS)'
    rm *.o
Zeth
  • 68
  • 6