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

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

问题描述

我已经尝试配置gtk +在visual studio但不能正常工作
任何人都可以建议我一个正确的解决方案,如何安装gtk在Visual studio 2010


<我得到GTK +使用VS2010,所以如果你想让它工作,准备好一些有趣的,因为这将需要几分钟。



首先,请下载最新的 Windows All-一体式套装。我使用的GTK 2.24软件包的可选直接下载链接此处。直接链接到32位版本。我尚未测试64位版本,因为它仍列为实验性质。



下载完成后,将其解压缩到 C:\gtk 或在我的情况下 D:\gtk



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



我们还要将GTK +构建的应用程序所需的.dll文件添加到我们的系统PATH中。为了简化操作,我建议您使用修改系统PATH PathEditor 。现在添加GDK二进制文件夹的路径,在我的例子是D:\gtk\bin到系统PATH。通过在命令提示符下键入 PATH ,确认GTK bin文件夹已添加到PATH。

现在我们继续使用Visual Studio 2010创建新项目。

 文件
- >新建
- >项目
Visual C ++
- > Win32
- > Win32控制台应用程序

应用程序向导出现。



点击选择:

  Windows应用程序

空项目

单击完成以继续。



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



应在您的包含目录中包含以下内容

  $(GTKDIR)\lib \gtk- 2.0 \include 
$(GTKDIR)\lib\glib-2.0\include
$(GTKDIR)\include

图书馆目录

  $ GTKDIR)\lib 

当我们仍然在项目属性视图中, >链接器,然后选择系统。在右侧找到子系统,然后点击下拉框。选择 Windows / SUBSYSTEM:WINDOWS



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

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

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

  -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 


我们将对链接器标记执行相同操作:

  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 ++ ,然后单击命令行。在右侧,您会看到一个名为其他选项的空框。将 compilerflags.txt 内容复制并粘贴到此框中。



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

最后,在源文件文件夹中,创建并添加一个带有以下内容的新的.cpp文件:

  #include< gtk-2.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 VS2010);

gtk_widget_show(window);

gtk_main();
return 0;
}

现在所有内容都可以编译,链接和运行了。如果一切顺利,您应该受到以下问候:



那很有趣,对吧? :)


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

解决方案

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.

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.

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

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

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:\gtk\bin to the system PATH. Confirm the GTK bin folder has been added to the PATH by typing PATH into your command prompt.

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.

Click to select:

Windows Application

Empty Project

click Finish to proceed.

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.

You should have the following in your Include Directories

$(GTKDIR)\lib\gtk-2.0\include
$(GTKDIR)\lib\glib-2.0\include
$(GTKDIR)\include

and Library Directories:

$(GTKDIR)\lib

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

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:\gtk\bin or %GTKDIR%\bin 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

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

My Result for linker flags:

/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

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.

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.

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

#include <gtk-2.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 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:

Well that was fun, right? :)

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

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