Gtk-ERROR **: GTK+ 2.x symbols detected - c

I'm compiling my c application with gcc with the following flags:
gcc evis.c `pkg-config --cflags --libs gtk+-2.0 --libs clutter-gtk-1.0 --libs gthread-2.0` -Wall -o evis
Now my code compiles with a few warnings but still finishes. When I try to run my program I get:
(evis:1820): Gtk-ERROR **: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported
How do I troubleshoot this error? How do I know where to look? Is there some kind of tool I could use online that would scan for GTK3 symbols in my code? I'm compiling with GTK+2 so I don't understand how this is happening.

You are linking the same program to Gtk+2.0 and Gtk+3.0. And that will not work.
It is easy to check: just run the pkg-config command standalone. BTW, you do not need to repeat --libs so many times, and since we are looking for linking errors, I'm ommiting the --cflags for clarity:
$ pkg-config --libs gtk+-2.0 clutter-gtk-1.0 gthread-2.0
Now, it writes a lot of library names, but if you look carefully you'll find these ones:
... -lgtk-x11-2.0 ... -lgtk-3 ...
But where do they come from? Well, the Gtk+-2 part is easy: you are asking for it in the command line! The Gtk+-3 part has only one candidate:
$ pkg-config --libs clutter-gtk-1.0
... -lgtk-3 ...
Bingo! So Clutter-gtk is a Gtk+-3 library. And so should be your program is you want to use Clutter-gtk.
The solutions to your problem are:
Port your program to Gtk+-3 and change your compiler command accordingly.
Use a different version of Clutter-gtk that uses Gtk+-2. I think you can choose the dependency if you compile Clutter-gtk yourself.
Do not use Clutter-gtk.

I had the same issue while using matplotlib package in python. The below code solved the issue for me
import matplotlib
matplotlib.use('Agg')

Related

how to add gtk in sublime text 3 to create graphical user interface for c programs

I'm learning c programming language. Almost I completed all the syntaxes and example programs. I want to create graphical user interface for the source code written in C. A lot of browsing in google I found that it is possible with gtk+. Now I'm using Sublime Text 3 to write and compile my C programs. Is there any way to add gtk+ with the sublimt text.
it's Been a while.
For those who stumble upon this..
Try the following:
click 'Tools' tab > 'Build System' > 'New Build System...'
in the file add the following:
{
"shell_cmd":"gcc `pkg-config --cflags gtk+-3.0` -o $file_base_name $file `pkg-config --libs gtk+-3.0`",
"selector":"source.c",
"working_dir":"$file_path"
}
save file with reasonable name. keeping in mind that this compiles for gtk3.0.
Note: this only compiles the current active single file.
Note 2: only tested in ST3.
You can use Make if you have it installed on your system. Or if it's just a single .c file, you can quickly use the command line. See this questions on how to compile and run C programs from within sublime text.
To get the CFLAGS and linking flags use:
pkg-config gtk+-3.0 --cflags --libs
As you have not stated the OS you are using I am going to assume Linux, or some Unix.
then:
gcc -Wall -Wpedantic -Wextra -g $(pkg-config gtk+-3.0 --cflags --libs) gtk.c -o gtk

GTK2.0 is installed but unable to locate when compiling

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`

How do I link GLFW

I am trying to link GLFW to my C program.
The docs seem to suggest #include<GLFW/glfw3.h> however I have installed 2.7.2 (from my distro's repository) and don't have that header file:
find / -name *glfw* 2> /dev/null
/usr/lib/libglfw.so.2.6
/usr/lib/libglfw.a
/usr/lib/libglfw.so
/usr/lib/pkgconfig/libglfw.pc
/usr/lib/libglfw.so.2
/usr/include/GL/glfw.h
/usr/share/doc/libglfw-dev
/usr/share/doc/libglfw2
/var/cache/apt/archives/libglfw2_2.7.2-1_i386.deb
/var/cache/apt/archives/libglfw-dev_2.7.2-1_i386.deb
/var/lib/dpkg/info/libglfw2.list
/var/lib/dpkg/info/libglfw2.postinst
/var/lib/dpkg/info/libglfw-dev.md5sums
/var/lib/dpkg/info/libglfw2.postrm
/var/lib/dpkg/info/libglfw2.md5sums
/var/lib/dpkg/info/libglfw2.shlibs
/var/lib/dpkg/info/libglfw-dev.list
I tried #include<GL/glfw.h> but I still get undefined reference to 'glfwLoadTexture2D'
How do I link to GLFW and use glfwLoadTexture2D()?
An #include does nothing for the linker; it just brings in declarations, not the actual functions.
The documentation indicates that GLFW uses pkg-config (not surprising; #elmindreda knows her stuff), so your compilation line should be something like:
$ cc `pkg-config --cflags glfw3` -o foo foo.c `pkg-config --static --libs glfw3`
Also note that since the library uses pkg-config, you're not supposed to "care" about details such as where the header and library files are located on your particular installation. Just ask using the --cflags and --libs modes, and you will get the proper locations returned, as the example above indicates.
You are mixing up compilation and linking. If you were missing headers, you would probably have errors a lot sooner than the linking stage.
"Undefined reference" results from symbols not being found by the linker. The most likely cause is you not telling gcc that it should link to the GLFW libraries:
gcc myfile.c -lglfw
When I am on Linux, I compile opengl/glfw projects like this:
gcc main.c -lGL -lglfw
When I am on windows, I compile them by writing:
gcc main.c libglfw3.a -lopengl32 -lgdi32
and I put libglfw3.a file in the same directory where main.c is. I have read people say that they couldn't link properly before writing
-lopengl32 -lgdi32 -luser32 -lkernel32 -lws2_32.
Another thing which may be worth mentioning is that I couldn't link glfw libraries when I downloaded 32bit glfw binaries. When I downloaded 64bit glfw binaries everything worked fine. I have a 64 bit machine and a x86_64-w64-mingw32. I have read comments from people with the opposite experience, where they weren't able to link glfw libraries when they downloaded 64bit binaries, but they were able to link them after downloading 32bit binaries. My advice would be to try both.

Set compiler path for OpenCV

I have been trying to run some sample c programs that uses the cv.h library, but what happened was that the compile complains the file could not be found. So I am guessing I need to some how set the compiler's path. How do I do that?
On linux, I use pkg-config to assist me on that task:
g++ program.cpp -o program `pkg-config --cflags --libs opencv`
With gcc, you need to add -I/path/to/the/folder/where/cv.h/is/. You'll probably also need the -L/path/to/the/folder/where/libopencv.so/is -lopencv.

Why can't I build a "hello world" for glib?

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.

Resources