GTK+ 3.0 setup in Visual Studio 2013

2019-02-25 14:29发布

问题:

So I'm trying to use GTK+ 3.0 in Visual Studio 2013, and I followed this tutorial:How to configure gtk on Visual studio 2010. The problem is that whenever I try to build the solution, I get Linker errors. I'm using this code:

    #include <gtk-3.0\gtk\gtk.h>

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

        GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        //gtk_widget_set_usize(window, 300, 200);

        g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
        gtk_window_set_title(GTK_WINDOW(window), "GTK+ with VS2013");

        gtk_widget_show(window);

        gtk_main(); 
        return 0;
    }

Each method call generates this type of error:

    Error   1   error LNK2019: unresolved external symbol _gtk_init_abi_check referenced in function _main

Things I have tried:
Adding the 'include' folders in the Linker's additional dependencies area, as well as the VC++ directories area under project settings
Checking that each .lib in the lib folder is accounted for in the Linker
This is the list I have:

    atk-1.0.lib cairo.lib fontconfig.lib gailutil.lib gdk-win32-3.0.lib gdk_pixbuf-2.0.lib gio-2.0.lib glib-2.0.lib gmodule-2.0.lib gobject-2.0.lib gthread-2.0.lib gtk-win32-3.0.lib pango-1.0.lib pangocairo-1.0.lib pangoft2-1.0.lib pangowin32-1.0.lib

Checking the compiler flags to ensure they're correct
This is the list of compiler flags I'm using:

    -IC:/gtk/include/gtk-3.0
    -IC:/gtk/lib/gtk-3.0/3.0.0 
    -IC:/gtk/include/atk-1.0
    -IC:/gtk/include/cairo
    -IC:/gtk/include/gdk-pixbuf-2.0
    -IC:/gtk/include/pango-1.0
    -IC:/gtk/include/glib-2.0
    -IC:/gtk/lib/glib-2.0/include
    -IC:/gtk/include
    -IC:/gtk/include/freetype2
    -IC:/gtk/include/libpng14
    -IC:/gtk/include/fontconfig
    -IC:/gtk/include/gail-3.0
    -IC:/gtk/include/gio-win32-2.0
    -IC:/gtk/include/jasper
    -IC:/gtk/include/librsvg-2.0
    -IC:/gtk/include/libxml2
    -IC:/gtk/include/lzma
    -IC:/gtk/include/pixman-1
    -IC:/gtk/lib/libffi-3.0.12/include

It seems as if the libraries just aren't being referenced properly, but I have no idea what else to try. Any suggestions are welcome!

回答1:

So for anyone who's interested; I figured it out! It's kind of a sloppy way to deal with things, but all I had to do was copy the .dll files into the Debug folder of the VS2013 project. Everything else works as expected!



回答2:

I followed the same steps and it worked for me. The includes and libs I use don't seem to contain any additional files.

In your build the Path to the GTK dlls seems to be unclear. Maybe you forgot to add the GTK dll dir (GTK\bin) to your system path?

You also have to assure that your build configuration matches the dlls, so win32 for dlls built as 32bit and x64 for dlls built as 64bit.