简体   繁体   English

在Windows下使用gcc安装gtk并进行编译?

[英]Installing gtk and compiling using gcc under windows?

I have gcc installed in c:/programfiles (also set as a path variable), and i have all the necessary files for gtk from http://www.gtk.org/download-windows.html , glib,gtk,pango,atk and cairo. 我在c:/ programfiles中安装了gcc(也设置为路径变量),我从http://www.gtk.org/download-windows.html,glib,gtk,pango获得gtk的所有必要文件, atk和cairo。 Although I have no clue as to how to compile ac program using gtk with the gcc compiler. 虽然我不知道如何使用gtk和gcc编译器编译ac程序。 How do I set everything up so that it works?. 如何设置所有内容以使其有效? (I don't know where each zip file goes.?) basically I don't really know where start. (我不知道每个zip文件的位置。?)基本上我真的不知道从哪里开始。

Ok, to install and use GTK+ in Windows and use it with MinGW you may follow these steps for example. 好的,要在Windows中安装和使用GTK +并将其与MinGW一起使用,您可以按照以下步骤操作。 I'll try to made them the easy, don't worry: 我会尽量让它们变得简单,不要担心:

  1. Install MinGW, as you've already done it so I wont elaborate this step. 安装MinGW,因为你已经完成了,所以我不会详细说明这一步。
  2. Download the GTK+ all-in-one bundle (there may be things you may not use... but this way should work). 下载GTK +一体化软件包 (可能有些东西你可能不会使用......但这种方式应该可行)。
  3. Decompress the contents of the bundle, you may do it in the same folder MinGW is installed or do it in another folder, it doesn't matter. 解压缩捆绑包的内容,你可以在MinGW安装的同一个文件夹中进行,或者在另一个文件夹中进行,没关系。
  4. Launch a command prompt, get to the bin directory where you extracted the bundle and run: 启动命令提示符,转到解压缩捆绑包的bin目录并运行:

    pkg-config --cflags --libs gtk+-win32-2.0

  5. It will print a list of compilation flags, and libraries to link your project to. 它将打印一个编译标志列表,以及将项目链接到的库。 Now, copy them and create a batch file (.bat or Windows Command Script .cmd) with the following: 现在,复制它们并使用以下命令创建批处理文件(.bat或Windows命令脚本.cmd):

    set VAR=FLAGS
    start cmd

    Where VAR is a name of a variable (for example GTK) and FLAGS is the output of the previous command ( pkg-config ). 其中VAR是变量的名称(例如GTK), FLAGS是上一个命令( pkg-config )的输出。

  6. Whenever you want to compile something that uses GTK+ double click that file, the GTK+ flags will be in VAR . 每当你想编译使用GTK +的东西双击该文件时,GTK +标志将在VAR You may compile this way for example: 你可以用这种方式编译,例如:

    gcc foo.c %VAR%

Instead of a batch file, you may find more convenient to create an user environmental variable and store the flags in there, that way you will be able to compile from within a normal command prompt. 您可能会发现创建用户环境变量并将标志存储在那里更方便,而不是批处理文件,这样您就可以在正常的命令提示符下进行编译。 I didn't describe that because the way to do it varies depending on the version of Windows you have. 我没有描述,因为这样做的方式因您拥有的Windows版本而异。 Generally you may find it in advanced system properties. 通常,您可以在高级系统属性中找到它。

Once you are more confident in GTK+ programming you may not use all of the packages, or all the flags, or reorder them in a different manner, use makefiles instead of having the compilation flags and the libraries in an environmental variable, ... 一旦你对GTK +编程更有信心,你可能不会使用所有的包或所有的标志,或者以不同的方式重新排序它们,使用makefile而不是在环境变量中使用编译标志和库,......

But by now, this will get you started. 但到现在为止,这将让你开始。

Also, you'll be linking dynamically to GTK+, so either the proper libraries are in the same directory of your project or are accessible from the path when you want to run it. 此外,您将动态链接到GTK +,因此正确的库位于项目的同一目录中,或者可以在运行它时从路径访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM