问题描述
我开始使用 C 在 GTK 中工作,并且我对Microsoft Visual Studio非常熟悉.我用于编译 codeblocks 或 devC ++ 甚至手动的 gcc 命令.但是我不知道是否有可能将 GTK 集成到 VS IDE 中,因为我知道 C 是可能的.我尝试了很多,但不幸的是没有成功.
I started working in GTK with C and I'm very familiar with Microsoft Visual Studio.I use for compiling codeblocks or devC++ and even manual gcc command. But I wonder if the is a possibility to integrate GTK to the VS IDE because I know it's possible for C. I tried a lot but unfortunately with no success.
谢谢
PS:我现在拥有VS 2017 RC,但我可以回到VS Community 2015.
PS: I have now VS 2017 RC but i can go back to VS Community 2015.
推荐答案
这是构建系统的一项工作.您应该尝试一个生成系统来为您的IDE生成项目文件.例如,CMake,或什至更好的介子构建系统,正在引起GNOME和GTK社区的关注.介子易于安装:它仅取决于python 3和ninja( make
的更快替代品).
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
).
首先,创建一个名为 meson.build
project('gtk test', 'c')
gtk_dep = dependency('gtk+-3.0')
executable('myapp', 'myapp.c',
dependencies : gtk_dep)
然后将您的应用程序代码放入 myapp.c
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;
}
最后,在Visual Studio环境中运行介子以进行检测.为此,请按照以下说明进行操作: https://github.com/mesonbuild/meson/wiki/Using-with-Visual-Studio
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
我从没尝试过在Windows上使用介子,但是我很确信这应该可行.欢迎提供有关体验的反馈意见:)
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:
这篇关于C&带有Microsoft Visual Studio IDE的GTK,这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!