I'm trying to compile a GTK program on my Debian desktop. I installed libgtk-3-dev and all of that, but when I go to compile the program, I get this error:
$ gcc -o client client.c `pkg-config --cflags --libs glib-2.0`
client.c:6:10: fatal error: gtk/gtk.h: No such file or directory
6 | #include <gtk/gtk.h>
| ^~~~~~~~~~~
compilation terminated.
All of the GTK headers actually seem to be in /usr/include/gtk-3.0, but even if I include <gtk-3.0/gtk/gtk.h> I get errors, since the files inside include other GTK headers as if they were in a normal include path. Then if I compile with -I/usr/include/gtk-3.0 I still get errors, this time about glib. Well, glib files are inside /usr/include/glib-2.0 and it's the same problem as before. Finally, if I compile with -I/usr/include/gtk-3.0 -I/usr/include/glib-2.0, I this time get this error:
$ gcc -o client -I/usr/include/gtk-3.0 -I/usr/include/glib-2.0 client.c `pkg-config --cflags $ --libs glib-2.0`
In file included from /usr/include/gtk-3.0/gdk/gdkapplaunchcontext.h:30,
from /usr/include/gtk-3.0/gdk/gdk.h:32,
from /usr/include/gtk-3.0/gtk/gtk.h:30,
from client.c:6:
/usr/include/gtk-3.0/gdk/gdktypes.h:35:10: fatal error: pango/pango.h: No such file or directory
35 | #include <pango/pango.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
Seems like any combination of compile flags I choose, I get some sort of error, all caused by Debian putting the headers in a non-standard subdirectory. This is not me messing with them, this is what apt installs for me.
You are asking pkg-config for glib, you must ask pkg-config for the GTK+ library:
gcc -o client client.c `pkg-config --cflags --libs gtk+-3.0`
You can keep glib-2.0 in the command line, but since GTK+ depends on glib, it's already included.
Related
I am trying to use gui with gkt-2.0 in Linux mint 32bit. When I try to compile gui.c I encountered following error message:
#include<gtk-2.0/gtk/gtk.h>
void main(){
}
In file included from gui.c:1:0:
/usr/include/gtk-2.0/gtk/gtk.h:32:10: fatal error: gdk/gdk.h: No such file or directory
#include <gdk/gdk.h>
^~~~~~~~~~~
When the appropriate packages are installed, you can add the needed include search directories with option -I, and the libraries of course -l, e.g.
gcc -I/usr/include/gtk-2.0 gui.c -o gui -lgtk-2.0
The source should be changed to
#include <gtk/gtk.h>
To avoid hard-coding any paths and names, you could use pkg-config (Compiling GTK Applications on UNIX)
gcc $(pkg-config --cflags gtk+-3.0) gui.c -o gui $(pkg-config --libs gtk+-3.0)
Better yet, use make or some other build tool.
I am brand new to GTK and looking to compile my first program with it. Upon compiling I get the following error:
randall#randall-ubuntu:~/c_programs/bettingCalc$ gcc -o bettingCalc main.c
main.c:8:21: fatal error: gtk/gtk.h: No such file or directory
#include <gtk/gtk.h>
^
compilation terminated.
The typical solution seems to be running the command:
sudo apt-get install libgtk2.0-dev
Which I ran, and seemingly successfully installed. What am I missing here?
if it is at all relevant, here is the last 8 lines of the installation process:
Setting up libxcomposite-dev (1:0.4.4-1) ...
Setting up x11proto-damage-dev (1:1.2.1-2) ...
Setting up libxdamage-dev:amd64 (1:1.1.4-1ubuntu1) ...
Setting up libxml2-utils (2.9.1+dfsg1-3ubuntu4.4) ...
Setting up libgtk2.0-dev (2.24.23-0ubuntu1.1) ...
Setting up libsys-hostname-long-perl (1.4-3) ...
Setting up libmail-sendmail-perl (0.79.16-1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.4) ...
randall#randall-ubuntu:~/c_programs/bettingCalc$
You have to use gtk-config in compile/link cycle to get info about installed GTK
http://manpages.ubuntu.com/manpages/intrepid/man1/gtk-config.1.html
UPDATE: gtk-config is depreciated, please use pkg-config to achieve desired result and get right
includes, flags and library references
For compilation
gcc -c main.c `pkg-config --cflags gtk+-2.0`
For linking
gcc -o app main.o `pkg-config --libs gtk+-2.0`
I just installed glib in Raspbian(Debian version). I want to read a config file using glib. I am trying to write a C application in Codeblocks and I use the header
#include <glib.h>
But I have an error in gtypes.h
fatal error:glibconfig.h No such file or directory
I used this path
project->Build Options->Compiler Settings->Other Options
and I added
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
as I read in this tutorial. I have to declare also
-L/usr/lib -lm -lglib-2.0
as the tutorial says and if yes then where and how can I declare it in Codeblocks?
Use pkg-config.
gcc `pkg-config --cflags glib-2.0` foo.c `pkg-config --libs glib-2.0`
I'm trying to use in one of my projects. I'm working on a Mac, have gotten MacPorts with pkg-config and glib-2.0 packages.
When I try to make a file containing an include to above path, I get the following error (line above it is for clarity that it does actually give me the right dirs):
$ pkg-config --cflags --libs glib-2.0
-I/opt/local/lib/glib-2.0/include -I/opt/local/include -L/opt/local/lib -lglib-2.0 -lintl
$ make
gcc hash-glib.c -c `pkg-config --cflags --libs glib-2.0` -std=c99 -Wall -Wextra -pedantic -O2
hash-glib.c:2:23: error: glib/glib.h: No such file or directory
$
Presumably, you've run:
ls -l /opt/local/lib/glib-2.0/include/glib/glib.h \
/opt/local/include/glib/glib.h
to demonstrate that the header #include "glib/glib.h" actually is present in one of the locations where you've been told by pkg-config that it could be found. If it isn't there, then pkg-config is misleading you, and the compiler is telling you that you've been hoodwinked.
Since the compiler will have done its utmost to find the header, it is a reasonable bet that the file isn't in either of those locations. You are then left with detective work: where is the glib.h header installed?
find /opt/local -type f -name glib.h
If that tells you where it is, you can then work out what pkg-config should be saying. If that fails to find it, widen the search area. If you still can't find it, maybe it isn't installed yet? Or you only installed the glib runtime, not the development package.
i have written a program under ubuntu, in which i include gtkmozembed.h. I am facing a problem in compiling the program.Below is the simplest form of a program which uses gtkmozembed.
#include <gtk/gtk.h>
#include <stdio.h>
#include <gtkmozembed.h>
int main(){
GtkWidget *mozEmbed;
mozEmbed = gtk_moz_embed_new();
return 0;
}
Eventhough, the above program is doing nothing, compiling that program is a lot for me...
I am trying to comile the above program like below
gcc `pkg-config --libs --cflags gtk+-2.0` test.c -o test
and it is giving the following error...
error: gtkmozembed.h: No such file or directory
I can understand, something else has to be added to the above gcc line,so that the compiler can find the gtkmozembed.h, but not getting what is that, 'something'...Looking for someone's help..Thank you...
Install libxul-dev (sudo apt-get install libxul-dev) and include
#include <gtkmozembed.h>
in the main file(test.c) and compile with
gcc `pkg-config --cflags --libs gtk+-2.0 xulrunner-gtkmozembed` test.c -o test
Your problem is that gtkmozembed.h is not found in the standard include file lookup path (well, the error does tell you that pretty obviously). On my system it lives in $(include)/gtkmozembed/, so you have two options
Change the path of the included file in your source
#include <gtkmozembed/gtkmozembed.h>
or manually add the path to the lookup path
gcc `pkg-config --libs --cflags gtk+-2.0` -I/usr/include/gtkmozembed test.c -o test
You should go with option 1).
This will tell gcc where to find the include file, but as pointed out by Matthew this is not enough: you will most probably also need to add more information for linking and required additional includes. Thankfully gtk-mozembed comes with a pkg-config file, so you can get all the needed information like you did for gtk+-2.0 with
pkg-config --libs --cflags mozilla-gtkmozembed-embedding
or combined with the other call
gcc `pkg-config --libs --cflags gtk+-2.0 mozilla-gtkmozembed-embedding` test.c -o test
You should also (just for kicks) have a look at what pkg-config does. The part in "`" is just what is return by the shell when executing that command. On my machine:
$ pkg-config --libs --cflags mozilla-gtkmozembed-embedding
-DXPCOM_GLUE -fshort-wchar \
-I/usr/include/xulrunner-1.9.2 -L/usr/lib/xulrunner-devel-1.9.2/lib -lxpcomglue
(line breaks added by me). The -I parts just adds additional needed directories to the include file lookup path -- they were emitted because you called with --cflags. The entries with -lxpcomglue is due to calling with --libs and ask for linking against this library, i.e. libxpcomglue.so. It is located in /usr/lib/xulrunner-devel-1.9.2/lib. The rest are a define and a gcc flag needed for gtkmozembed.
Try this:
gcc `pkg-config --libs --cflags gtk+-2.0 mozilla-gtkmozembed-embedding` test.c -o test