如何在 Visual Studio 2010 上配置 gtk [英] How to configure gtk on Visual studio 2010

查看:48
本文介绍了如何在 Visual Studio 2010 上配置 gtk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试在 Visual Studio 上配置 gtk+,但无法正常工作.,任何人都可以向我建议适当的解决方案,例如如何在 Visual Studio 2010 上安装 gtk

I have tried configuring gtk+ on visual studio but doesn't work properly., Can anyone suggest me with a proper solution, as how to install gtk on Visual studio 2010

推荐答案

我让 GTK+ 与 VS2010 一起工作,所以如果你也想让它工作,准备一些乐趣,因为这需要几分钟.

I got GTK+ working with VS2010, so if you want to get it working too, get ready for some fun, because this will take a few minutes.

首先,下载最新的 Windows All-In-One bundle.我使用的 GTK 2.24 包的可选直接下载链接 此处.直接链接是 32 位版本.我还没有测试 64 位版本,因为它仍然被列为实验性的.

First of all, download the latest Windows All-In-One bundle. Optional direct download link for the GTK 2.24 bundle that I used here. The direct link is to the 32bit version. I have not tested the 64bit version because it is still listed as experimental.

下载捆绑包后,将其解压缩到C:gtk 或在我的情况下D:gtk

Once you have the bundle downloaded, unzip it into something like C:gtk or in my case D:gtk

接下来我们将为 GTK 文件夹创建一个系统环境变量.打开命令提示符并写入: setx GTKDIR {Path to your GTK folder}/m 在我的例子中是 setx GTKDIR D:gtk/m

Next we will create a System Environment Variable for the GTK folder. Open up a command prompt and write: setx GTKDIR {Path to your GTK folder} /m which in my case would be setx GTKDIR D:gtk /m

我们还将把 GTK+ 构建的应用程序在 Windows 上运行所需的 .dll 文件添加到我们的系统路径中.为了让事情变得非常简单,我建议您使用 PathEditor 编辑您的系统路径.现在将 GDK 二进制文件夹的路径添加到系统路径中,在我的例子中是 D:gtkin.通过在命令提示符中键入 PATH 来确认 GTK bin 文件夹已添加到 PATH 中.

We are also going to add the .dll files required for GTK+ built applications to run on Windows into our system PATH. To make things very easy, I suggest you edit your system PATH with PathEditor. Now add the path to the GDK binaries folder which in my case is D:gtkin to the system PATH. Confirm the GTK bin folder has been added to the PATH by typing PATH into your command prompt.

现在我们转到 Visual Studio 2010 并创建一个新项目.

Now we move on to Visual Studio 2010 and create a new project.

File
  ->New
    ->Project
    Visual C++
      ->Win32
        ->Win32 Console Application

然后出现应用程序向导.

Then the Application Wizard Appears.

点击选择:

Windows Application

Empty Project

点击完成继续.

在我们添加任何源文件之前,右键单击解决方案资源管理器中的项目名称,然后单击属性.现在转到配置属性,然后转到VC++ 目录.我们现在需要将包含和库文件从 GTK 添加到包含目录库目录.

Before we add any source files, right click on the project name in the Solution Explorer and click on Properties. Now go to Configuration Properties and then VC++ Directories. We now need to add the include and library files from GTK to the Include Directories and Library Directories.

您的包含目录

$(GTKDIR)libgtk-2.0include
$(GTKDIR)libglib-2.0include
$(GTKDIR)include

图书馆目录:

$(GTKDIR)lib

当我们仍处于项目属性视图中时,点击链接器,然后点击系统.在右侧查找 SubSystem,然后单击下拉框.选择 Windows/SUBSYSTEM:WINDOWS

While we are still in the view of the Project Properties, click on Linker and then System. Look for SubSystem on the right and click the drop down box. Select Windows /SUBSYSTEM:WINDOWS

接下来,我们必须为编译器和链接器生成标志.幸运的是,GTK+ 附带了一个名为 pkg-config 的不错的小工具,我们将使用它为我们自动生成这些标志.pkg-config 工具可以在 GTK 的 bin 文件夹中找到.就我而言,这是使用我们之前定义的系统变量的 D:gtkin%GTKDIR%in.只需使用命令提示符导航到 bin 文件夹(创建的文本文件将在那里输出)并运行以下命令:

Next up, we have to generate the flags for the compiler and the linker. Luckily, GTK+ comes with a nice little tool called pkg-config that we will use to automatically generate these flags for us. The pkg-config tool can be found in the bin folder of GTK. In my case this is D:gtkin or %GTKDIR%in using our system variable that we defined earlier. Simply navigate to the bin folder(the created text files will be output there) using the command prompt and run the following:

pkg-config --cflags gtk+-2.0 --msvc-syntax > compilerflags.txt

这将创建我们需要的编译器标志并将它们存储在一个文本文件中.我的编译器标志结果(我已删除标志 -mms-bitfields,这是我们不需要的仅 gcc 标志):

This will create the compiler flags we need and store them in a text file. My Result for compiler flags (I have removed the flag -mms-bitfields, this is a gcc only flag that we don't need):

-ID:/gtk/include/gtk-2.0 -ID:/gtk/lib/gtk-2.0/include -ID:/gtk/include/atk-1.0 -ID:/gtk/include/cairo -ID:/gtk/include/gdk-pixbuf-2.0 -ID:/gtk/include/pango-1.0 -ID:/gtk/include/glib-2.0 -ID:/gtk/lib/glib-2.0/include -ID:/gtk/include -ID:/gtk/include/freetype2 -ID:/gtk/include/libpng14

我们将对链接器标志做同样的事情:

We will do the same for the linker flags:

pkg-config --libs gtk+-2.0 --msvc-syntax > linkerflags.txt

我的链接器标志结果:

/libpath:D:/gtk/lib gtk-win32-2.0.lib gdk-win32-2.0.lib atk-1.0.lib gio-2.0.lib pangowin32-1.0.lib gdi32.lib pangocairo-1.0.lib gdk_pixbuf-2.0.lib pango-1.0.lib cairo.lib gobject-2.0.lib gmodule-2.0.lib gthread-2.0.lib glib-2.0.lib intl.lib

生成所有需要的标志后,我们需要将它们添加到我们的项目中.再次右键单击项目名称,然后单击属性.现在转到 C/C++ 并单击 Command Line.在右侧,您应该会看到一个名为其他选项的空框.将 compilerflags.txt 内容复制并粘贴到此框中.

With all the needed flags generated, we need to add them to our project. Once again, right click on the project name and click on Properties. Now go to C/C++ and click on Command Line. To the right you should see an empty box called Additional Options. Copy and paste the compilerflags.txt content into this box.

完成上述操作后,点击链接器,然后点击命令行.同样,只需将 linkerflags.txt 文件的内容复制并粘贴到其他选项框中即可.当我们在这里时,添加最后一个链接器标志 /ENTRY:mainCRTStartup 该标志告诉 Visual Studio 我们要使用标准 main() 而不是 Microsoft 的 _tmain() 作为我们的主程序入口点.

After finishing the above, click on Linker and then Command Line. Once again, simply copy and paste the contents of the linkerflags.txt file into the Additional Options box. While we are here, add one last linker flag /ENTRY:mainCRTStartup This flag tells Visual Studio that we want to use the standard main() rather than Microsoft's _tmain() as our main program entry point.

最后,在 Source Files 文件夹中,创建并添加一个新的 .cpp 文件,内容如下:

Finally, in the Source Files folder, create and add a new .cpp file with the following:

#include <gtk-2.0gtkgtk.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 VS2010");

    gtk_widget_show(window);     

    gtk_main();   
    return 0;
}

现在一切都应该可以编译、链接和运行了.如果一切顺利,您应该看到以下内容:

Everything should now be ready to compile, link and run. If all went well, you should be greeted by the following:

那很有趣,对吧?:)

这篇关于如何在 Visual Studio 2010 上配置 gtk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆