Thread: GTK+ - Problems installing dev-lib

  1. #1
    Registered User
    Join Date
    Mar 2017
    Posts
    26

    GTK+ - Problems installing dev-lib

    So i have spent the better part of a day now trying to work this out myself, however i feel I'm almost at the point where it's becoming counter productive, as I've tried everything i can think of, including using apt to install from the official repos and also downloaded source and built the library that way... I have actually installed GTK in the past, however this was some time ago and i remember having issues that time, but from memory, building from source fixed whatever problem i had back then.

    Then i went to use the library again recently and it was not working, however i think i may have reinstalled Linux since then.
    So i try install using apt, it just installs a bunch of other packages, and the #include in my C program does not find the library at all.
    Then i download and build from source, my IDE recognizes the library, but none of the functions are recognized? I am using CLION, but i also had no luck trying to compile a program from the terminal.

    What could i possibly be doing wrong?

    This is compiler output.. But regardless of this, still none of the functions are recognized?

    Code:
    [ 50%] Building C object CMakeFiles/gtkz3.dir/main.c.o
    In file included from /root/CLionProjects/gtkz3/main.c:1:0:
    /usr/include/gtk-3.0/gtk/gtk.h:30:21: fatal error: gdk/gdk.h: No such file or directory
     #include <gdk/gdk.h>
                         ^
    compilation terminated.
    CMakeFiles/gtkz3.dir/build.make:62: recipe for target 'CMakeFiles/gtkz3.dir/main.c.o' failed
    make[3]: *** [CMakeFiles/gtkz3.dir/main.c.o] Error 1
    CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/gtkz3.dir/all' failed
    make[2]: *** [CMakeFiles/gtkz3.dir/all] Error 2
    CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/gtkz3.dir/rule' failed
    make[1]: *** [CMakeFiles/gtkz3.dir/rule] Error 2
    Makefile:118: recipe for target 'gtkz3' failed
    make: *** [gtkz3] Error 2
    I installed Curl, OpenSSL, and other libraries recently with no problem, i'm not sure why GTK always gives me so much trouble.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Just saying "using apt to install" and "compile a program from the terminal" tells us very little. HOW did you use apt? HOW did you compile the program? Show the exact command lines (look them up in your history). Also, mentioning your distro might be helpful. And showing the includes in your program could be useful, too.

  3. #3
    Registered User
    Join Date
    Mar 2017
    Posts
    26
    I am using an install of Kali Linux. The thing is, I've tried almost every way possible to install using apt, as in multiple variants of gtk+-3.0 package name. I have a .bashrc entry that deletes .bash_history file but looking at /var/log/apt/history.log, some variations were libgtk-3-dev, gtk-3.0-dev, gtk+-3.0-dev, libgtk+3.0. I tried using #include <gtk/gtk.h> and that failed, failed as in could not find the .h file at all. I then realized that there was no obvious sign that GTK had installed into either /usr/include or /usr/local/include directory, So i removed every package i installed on that day, and downloaded from source. I then did as i normally do and run the configure script ./configure with no other flags, and then make, then make install.. This installed into /usr/local/include, with a top level directory name "gtk-3.0" so i tried #include <gtk-3.0/gtk/gtk.h> and then at that point the IDE found that header file, but when i tried using the functions included in the library, they were not recognized. At this point i opened up the header file and found that there were includes such as #include <gdk/gdk.h> and other <gtk/xx> headers that were highlighted in red, from what i can tell, this means it couldn't find the path to those other includes within <gtk/gtk.h>

    And i tried to repeat these steps multiple times but eventually i just gave up because i didn't want to make more of a mess of things..
    Last edited by Strobez; 04-07-2017 at 04:17 AM.

  4. #4
    Registered User
    Join Date
    Sep 2014
    Posts
    364
    You use 'apt' to install packages, so i think Kali Linux is based on Debian Linux.
    If I search for files, I use 'apt-file'. You can install 'apt-file' with:
    Code:
    #apt install apt-file
    This tool need a database to locate all known files that was shipped with all packages.
    To update the database, use:
    Code:
    #apt-file update
    Now you can search for every package that contain a specific file.
    Here I have searched for 'gtk/gtk.h':
    Code:
    $ apt-file find gtk/gtk.h
    libgtk-3-dev: /usr/include/gtk-3.0/gtk/gtk.h
    libgtk2.0-dev: /usr/include/gtk-2.0/gtk/gtk.h
    I think the first line is what you need.
    The file '/usr/include/gtk-3.0/gtk/gtk.h' is included in 'libgtk-3-dev'.
    Other have classes, we are class

  5. #5
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    "Kali Linux is a Debian-derived Linux distribution designed for digital forensics and penetration testing."

    Anyway, the first possibility is that gtk3 is already installed (why not?).

    What does this show?
    dpkg -l libgtk* | grep ^i

    Your apt-get line should have been:
    apt-get install libgtk-3-dev

    This assumes that libgtk-3-dev is available in the repositories you have listed in /etc/apt/sources.list (This page seems to suggest that you should only have one repository listed there.

    To compile from source you need to read this and this.

    In your code, you only need to say #include <gtk/gtk.h>. For the compilation step, the headers are found by passing the appropriate -I flags to gcc. For the linking step, the libaries are found by passing the appropriate -l flags.

    The usual way to compile is to use pkg-config which automatically adds the appropriate flags:
    gcc myprog.c $(pkg-config --libs --cflags gtk+-3.0) -o myprog

    This assumes pkg-config is installed and the appropriate .pc file has been installed in the proper location.

  6. #6
    Registered User
    Join Date
    Mar 2017
    Posts
    26
    I have installed "apt-file" and that's okay, the output was exactly as yours shows in the example. But there's still a bunch of problems that seem to be possibly caused by dependencies such as glib. These dependencies are all installed though. And i did not have this much trouble last time i installed and used GTK. Is there some way i can fix all the dependency problems? Right now the only thing that seems to resolve the compiler errors is by adding a bunch of include_directories() in the CMakeLists.txt file for the project. But I'm not really prepared to sit and add them all one by one like that as i know there is obviously some problem seeing as i have never had to do such a thing in the past.

  7. #7
    Registered User
    Join Date
    Mar 2017
    Posts
    26
    This is the output of aforementioned command.

    Code:
    ii  libgtk-3-0:amd64             3.22.11-1    amd64        GTK+ graphical user interface library
    ii  libgtk-3-bin                 3.22.11-1    amd64        programs for the GTK+ graphical user interface library
    ii  libgtk-3-common              3.22.11-1    all          common files for the GTK+ graphical user interface library
    ii  libgtk-3-dev:amd64           3.22.11-1    amd64        development files for the GTK+ library
    ii  libgtk-3-doc                 3.22.11-1    all          documentation for the GTK+ graphical user interface library
    ii  libgtk2-perl                 2:1.2499-1   amd64        Perl interface to the 2.x series of the Gimp Toolkit library
    ii  libgtk2.0-0:amd64            2.24.31-2    amd64        GTK+ graphical user interface library
    ii  libgtk2.0-bin                2.24.31-2    amd64        programs for the GTK+ graphical user interface library
    ii  libgtk2.0-common             2.24.31-2    all          common files for the GTK+ graphical user interface library
    ii  libgtkmm-2.4-1v5:amd64       1:2.24.5-1   amd64        C++ wrappers for GTK+ (shared libraries)
    ii  libgtkmm-3.0-1v5:amd64       3.22.0-1     amd64        C++ wrappers for GTK+ (shared libraries)
    ii  libgtksourceview-3.0-1:amd64 3.22.2-1     amd64        shared libraries for the GTK+ syntax highlighting widget
    ii  libgtksourceview-3.0-common  3.22.2-1     all          common files for the GTK+ syntax highlighting widget
    ii  libgtksourceview2.0-0:amd64  2.10.5-3     amd64        shared libraries for the GTK+ syntax highlighting widget
    ii  libgtksourceview2.0-common   2.10.5-3     all          common files for the GTK+ syntax highlighting widget
    ii  libgtkspell3-3-0:amd64       3.0.9-1      amd64        spell-checking addon for GTK+'s TextView widget
    Even after seemingly removing all the packages i downloaded, and the directory that was the result of building from source, then trying to install libgtk-3-dev again (using apt). Still no luck, it seems I've somehow made a mess of the dependencies as they seem to not be installed where GTK is expecting them to be.
    I'm almost thinking it would be less issue to backup my data and reinstall Linux again, i just hoped i could figure out why there's been an issue this time, i don't remember doing anything different the last time i used GTK.
    Last edited by Strobez; 04-07-2017 at 10:17 AM.

  8. #8
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    So you tried compiling from the command line with pkg-config as I showed and it still didn't work?

  9. #9
    Registered User
    Join Date
    Mar 2017
    Posts
    26
    Ok sorry, When i compile an example program using the terminal exactly as you described, it works, i still get a message 'failed to load module "canberra-gtk-module"', but it does compile, and it opens a window, however when i try in CLion IDE it does not compile, and does not at all recognize any functions used in the program. But this is the only library that i am experiencing this problem with.

  10. #10
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    I don't know CLion, but you need to add `pkg-config --cflags gtk+-3.0` to the compile options and `pkg-config --libs gtk+-3.0` to the linker options.
    Alternatively, you could run those commands in a terminal (obviously without the backticks) and copy/paste the output.

    As for the problem with canberra-gtk-module, try google.

  11. #11
    Registered User
    Join Date
    Mar 2017
    Posts
    26
    I think modifying CMake file has helped with the issue of not finding functions, aside from one, being gtk_application_window_new() ?.

    Here's my CMake file

    Code:
    cmake_minimum_required(VERSION 3.7)
    project(gtkz3)
    
    set(CMAKE_C_STANDARD 99)
    
    set(SOURCE_FILES main.c)
    add_executable(gtkz3 ${SOURCE_FILES})
    find_package(PkgConfig)
    if (PKG_CONFIG_FOUND)
        pkg_check_modules(GTK "gtk+-3.0")
        if (GTK_FOUND)
            target_link_libraries(gtkz3 ${GTK_LIBRARIES})
            add_definitions(${GTK_CFLAGS} ${GTK_CFLAGS_OTHER})
        endif()
    endif()
    Any suggestions as to why there's now an error resolving just that one funtion?

    Here's the example code i'm using from gnome.org

    Code:
    #include <gtk/gtk.h>
    
    static void activate (GtkApplication* app, gpointer        user_data)
    {
        GtkWidget *window;
        window = gtk_application_window_new(app);  //Cannot resolve this function?
        gtk_window_set_title (GTK_WINDOW (window), "Window");
        gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
        gtk_widget_show_all (window);
    }
    
    int main (int    argc, char **argv) {
        GtkApplication *app;
        int status;
    
        app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
        g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
        status = g_application_run (G_APPLICATION (app), argc, argv);
        g_object_unref (app);
    
        return status;
    }

  12. #12
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Try this:
    Code:
    cmake_minimum_required(VERSION 3.7)
    project(gtkz3 C)
    set(CMAKE_C_STANDARD 99)
    set(SOURCE_FILES main.c)
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
    include_directories(${GTK3_INCLUDE_DIRS})
    link_directories(${GTK3_LIBRARY_DIRS})
    add_definitions(${GTK3_CFLAGS_OTHER})
    add_executable(gtkz3 ${SOURCE_FILES})
    target_link_libraries(gtkz3 ${GTK3_LIBRARIES})
    Last edited by algorism; 04-07-2017 at 11:30 AM.

  13. #13
    Registered User
    Join Date
    Mar 2017
    Posts
    26
    It seems after restarting my system and running the IDE again it's managed to resolve the function
    And i'm almost 100% sure it wasn't this difficult last time. :S
    At least it is working now.
    Thanks heaps for the help, it's very much appreciated.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems installing Mingw5.1.4
    By BlackOps in forum C Programming
    Replies: 2
    Last Post: 07-26-2009, 03:28 AM
  2. Problems installing gtk
    By hallo007 in forum Linux Programming
    Replies: 4
    Last Post: 06-26-2007, 02:26 PM
  3. Problems installing GTKmm
    By LiKWiD in forum C++ Programming
    Replies: 6
    Last Post: 03-29-2004, 11:31 PM
  4. problems Installing stlport with vc7
    By silk.odyssey in forum C++ Programming
    Replies: 0
    Last Post: 12-22-2003, 09:09 AM
  5. Installing XP....Problems
    By MethodMan in forum Tech Board
    Replies: 14
    Last Post: 11-01-2002, 03:01 PM

Tags for this Thread