Solved Compiler path to header files

I am going to do the tutorials in "Foundations of GTK" book and I am wondering if my paths for compiling are setup correctly.
Where would I modify to include gtk.h.
My header currently uses the whole path to find gtk.h and that works.
It does not seem like this is correct as most tutorials use /gtk/gtk.h as the header path.
Am I doing the right thing?
/usr/local/include does not seem to be included in the compiler header path but /usr/include is.
It seems like my `pkgconf` part of my compile command may be wrong.
Can I get some guidance please. Most examples use gcc versus clang. Should I be using gcc?
Here is my compile command:
cc `pkgconf --cflags gtk+-3.0` first.c -o first.app `pkgconf --libs gtk+-3.0` -rdynamic -Wall

My first assignment:
Code:
#include </usr/local/include/gtk-3.0/gtk/gtk.h>

int main(int argc, char *argv[]) {

  GtkWidget *window;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "First Project");
  gtk_widget_show(window);

  g_signal_connect(window, "destroy",
      G_CALLBACK(gtk_main_quit), NULL);

  gtk_main();

  return 0;
}
 
I fooled with moving the path from the gtk.h header to the CFLAG option for compiling.
cc `pkgconf --cflags /usr/local/include/gtk-3.0` first.c -o first.app `pkgconf --libs /usr/local/include/gtk-3.0` -rdynamic -Wall
But that failed. The compiler gave some good tips. I need to look at the search path for pkgconf compiling option.
Code:
Package /usr/local/include/gtk-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `/usr/local/include/gtk-3.0.pc'
to the PKG_CONFIG_PATH environment variable
Package '/usr/local/include/gtk-3.0', required by 'virtual:world', not found
Package /usr/local/include/gtk-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `/usr/local/include/gtk-3.0.pc'
to the PKG_CONFIG_PATH environment variable
Package '/usr/local/include/gtk-3.0', required by 'virtual:world', not found
first.c:1:10: fatal error: '/gtk/gtk.h' file not found
#include </gtk/gtk.h>
         ^~~~~~~~~~~~
1 error generated.
 
Not much of a programmer but you can get a list of "packages" by using pkgconf --list-all. One of the packages that's installed on my system is called gtk+-3.0, and you can use it like this: pkgconf --libs 'gtk+-3.0' and it will print a line of compiler options providing the include files and library locations.

Code:
# pkgconf --libs 'gtk+-3.0'
-L/usr/local/lib -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lpthread -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl

Note though that I used GTK+ as an example, you would need to find the correct one for your situation. But this should provide you some clues on how to use it.
 
Set the "I" and "L" switches to point to /usr/local/include and /usr/local/lib.

eg. cc first.c -I/usr/local/include -L/usr/local/lib -o first.app
 
I fixed this by dropping off -rdynamic from the compiler.
With SirDice advice I could tell that pkgconf was OK. So I looked elsewhere.

Code:
root@E6420:/gtk # pkgconf --libs 'gtk+-3.0' -L/usr/local/lib -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lpthread -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lint
 
I like to have source code verification and linting in my vim editor while coding. To resolve this in a general manner I configured the next environment variables in my shell (~/.profile or ~/.bashrc):
Code:
# Where to look for includes
export CPATH="$CPATH:/usr/local/include"
Code:
# Where to look for packages when working with pkgconf
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/binary/libs/includes/pkgconfig/"
This resolved any issue with /usr/local/... for vim and any other command I executed in the shell.
 
Back
Top