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.
Related
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.
Working on a GTK++ project. The thing compiled successfully when using Ubuntu's libgtk2.0-dev library. After removing that library and installing libgtk3.0-dev library, I get the following error message at compile time:
In file included from file_operations.c:4:0:
/usr/include/gtk-3.0/gdk/gdkevents.h:26:2 #error: Only <gdk/gdkh> can be included directly.
Here is the compile command:
gcc -Wall -o gexplorer2 main.c file_operations.c -I. -I/usr/include/gnome-vfs-2.0 -D _FILE_OFFSET_BITS=64 `pkg-config --cflags gtk+-3.0` `pkg-config --libs gtk+-3.0` `pkg-config --cflags gio-2.0`
file_operations.c has the following includes:
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <gdk/gdkevents.h>
In gdkevents.h, the following lines generate the compiler error
#if !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION)
#error "Only <gdk/gdkh> can be included directly."
#endif
(These lines were not in GTK 2.0's include files.)
Guesses or knowledge on what is causing this error, and how to resolve?
The idea here seems to be that the GDK authors want to discourage you from including specific GDK headers directly (presumably because those headers have subtle dependencies that are not spelled out with explicit includes).
So just do what they say, remove your <gdk/x> includes and include <gdk/gdkh> instead. Presumably, that should include the APIs you want.
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 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
So here's the world's simplest glib program:
#include <glib.h>
I try to compile it with gcc test.c and I get:
test.c:1:18: error: glib.h: No such file or directory
So I make sure that I have the right packages:
# dpkg -l | grep libglib
ii libglib-perl 1:1.183-1 Perl interface to the GLib and GObject libra
ii libglib1.2-dev 1.2.10-19build1 The GLib library of C routines (development)
ii libglib1.2ldbl 1.2.10-19build1 The GLib library of C routines
ii libglib2.0-0 2.20.1-0ubuntu2 The GLib library of C routines
ii libglib2.0-cil 2.12.1-1ubuntu2 CLI binding for the GLib utility library 2.1
ii libglib2.0-data 2.18.2-0ubuntu2 Common files for GLib library
ii libglib2.0-dev 2.20.1-0ubuntu2 Development files for the GLib library
ii libglibmm-2.4-1c2a 2.18.1-1 C++ wrapper for the GLib toolkit (shared lib
Then I search for any "glib.h" anywhere under /usr/include. I get two, /usr/include/glib-1.2/glib.h and /usr/include/glib-2.0/glib.h. So I try:
$ gcc -I/usr/include/glib-2.0 -Wall test.c
In file included from /usr/include/glib-2.0/glib/galloca.h:34,
from /usr/include/glib-2.0/glib.h:32,
from test.c:2:
/usr/include/glib-2.0/glib/gtypes.h:34:24: error: glibconfig.h: No such file or directory
(about 10,000 more errors snipped)
I don't seem to have a glibconfig.h anywhere on my computer.
What do I do now?
glib tends to hide itself... Your include statement doesn't work because GCC doesn't automatically search subdirectories, and so cannot see the glib.h in glib-1.2 or glib-2.0.
Read the Compiling GLib Applications page in the GLIB manuals... you use commands like pkg-config --cflags glib-2.0 to get the right flags for GCC.
The canonical way to do what you are trying is
% gcc test.c -Wall -o test `pkg-config --cflags --libs glib-2.0`
Note the back-ticks, which tell the shell to run the pkg-config command "in-place".
> > The canonical way to do what you are trying is
> % gcc test.c -Wall -o test `pkg-config --cflags --libs glib-2.0`
Sorry, but no. That is a common misconception, that just happens to work in most cases on ELF-based systems, Linux in particular. The canonical way is to pass in the cflags and libraries separately, in the correct and traditional locations on the command line, like this:
gcc -Wall -o test `pkg-config --cflags glib-2.0` test.c `pkg-config --libs glib-2.0`
It is a pity that pkg-config accepts both the --cflags and --libs options at the same time, as it means this incorrect meme will never die, and people used to it on Linux will continue to be baffled when they then try the same on other platforms.
As #chris said use pkg-config.
glibconfig.h is missing
it’s because this file is not in the /usr/include/glib-2.0, but in /usr/lib/glib-2.0. So you have to include also this /usr/lib path or copy the file to the /include/glib-2.0
I am using glib.h as well-
Do this to compile all your glib.h programs :)
gcc `pkg-config --cflags --libs glib-2.0` filename.c
Make sure to surround pkg-config --cflags --libs glib-2.0 with back-quotes
which you find under tilde (left most key on the querty keyboard).
Thank me later .. :P
apt-get build-dep is your friend -- nobody can remember all the packages you need to build something.