Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'gtk/gtk.h' file not found Even with pkg-config

I'm creating a software in C using the SDL library and GTK+3. My first attempt with GTK+3 on a specific main.c and its Makefile works well, but when I try to add my GTK project to the other piece of code using my "real" Makefile, even if I added the same flags for GTK+3, I can't compile and get the gtk/gtk.h file no found error. I visited many threads about this error but I still can't make it work.

Here's my old Makefile, making things work:

CC=clang
CPPFLAGS= `pkg-config --cflags gtk+-3.0`
CFLAGS= -Wall -Wextra -std=c99 -O2
LDFLAGS=
LDLIBS= `pkg-config --libs gtk+-3.0` `pkg-config gmodule-2.0 --libs`
SRC= main.c
OBJ= ${SRC:.c=.o}
all: main
main: ${OBJ} -lm
clean:
rm -f *~ *.o main

And here's the one I use for the project:

CC=clang

CPPFLAGS= `pkg-config --cflags sdl gtk+-3.0`
CFLAGS= -Wall -Wextra -Werror -std=c99 -O2 -pedantic
LDFLAGS=
LDLIBS= `pkg-config --libs sdl` `pkg-config --libs gtk+-3.0` `pkg-config  gmodule-2.0 --libs` -lgtk -lgdk -lglib -lX11 -lXext -lSDL -lSDL_image -lm

SRCDIR   = src
OBJDIR   = obj
BINDIR   = bin

TARGET = main

SOURCES  := $(wildcard $(SRCDIR)/*.c)
INCLUDES := $(wildcard $(SRCDIR)/*.h)
DEPENDS  := $(wildcard $(OBJDIR)/*.d)
OBJECTS  := $(SOURCES:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
rm       = rm -f

all: makedirs $(BINDIR)/$(TARGET)

$(BINDIR)/$(TARGET): $(OBJECTS)
@$(CC) $(OBJECTS) $(LDLIBS) -o $@
@echo "Linking complete!"

$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
@$(CC) $(CFLAGS) -c $< -o $@
@echo "[OK] Compiled "$<""

makedirs:
@mkdir -p $(OBJDIR)
@mkdir -p $(BINDIR)
@echo "[OK] Created directories : $(BINDIR) $(OBJDIR)"
[....] etc

And the error:

src/main.c:2:14: fatal error: 'gtk/gtk.h' file not found
#include <gtk/gtk.h>

Tanks for the attention :)

[EDIT]

~                                                                              
  ▶ pkg-config --libs gtk+-3.0
  -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 

  ~                                                                              
  ▶ pkg-config --cflags sdl gtk+-3.0
  -D_GNU_SOURCE=1 -D_REENTRANT -pthread -I/usr/include/SDL -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/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 

And the header of main.c:

  #include <gtk/gtk.h>    
  #include <stdio.h>    
  #include <stdlib.h>     
  #include "neural.h"
like image 785
LeCoon zarakailloux Avatar asked Dec 02 '16 17:12

LeCoon zarakailloux


1 Answers

As Y. Verzun said, I forgot to add the CPPFLAGS rule, but not only to the OBJECTS:

$(BINDIR)/$(TARGET): $(OBJECTS)
@$(CC) $(OBJECTS) $(LDLIBS) $(CPPFLAGS) -o $@
@echo "Linking complete!"

$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
@$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
@echo "[OK] Compiled "$<""

here's the code working, notice both of the $(CPPFLAGS) added. Thanks a lot !

like image 155
LeCoon zarakailloux Avatar answered Oct 02 '22 15:10

LeCoon zarakailloux