This is a job for your build system. You should try a build system that generates project files for your IDE. For example, CMake, or even better, the meson build system, which is getting some attention on the GNOME and GTK community. Meson is easy to install: it only depends on python 3 and ninja (a faster replacement for make
).
First, create a file named meson.build
project('gtk test', 'c')
gtk_dep = dependency('gtk+-3.0')
executable('myapp', 'myapp.c',
dependencies : gtk_dep)
Then put your application code in myapp.c
#include <gtk/gtk.h>
int
main (int argc, char **argv)
{
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Hello world !");
g_signal_connect (G_OBJECT (window), "destroy", gtk_main_quit, NULL);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
Finally, run meson in your Visual Studio environment to detect it. For that, follow the instructions at:
https://github.com/mesonbuild/meson/wiki/Using-with-Visual-Studio
I never tried to use meson on Windows, but I'm pretty confident this should work. Feedback about the experience is welcome :)
Here are additional links to the meson documentation: