windows下安装gtk和gcc编译? [英] Installing gtk and compiling using gcc under windows?

查看:36
本文介绍了windows下安装gtk和gcc编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 c:/programfiles 中安装了 gcc(也设置为路径变量),并且我拥有来自 http://www.gtk.org/download-windows.html、glib、gtk、pango、atk 和 cairo.虽然我不知道如何使用 gtk 和 gcc 编译器编译 c 程序.我如何设置一切以使其正常工作?(我不知道每个 zip 文件去哪里.?)基本上我真的不知道从哪里开始.

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. Although I have no clue as to how to compile a c program using gtk with the gcc compiler. 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.

推荐答案

好的,例如,要在 Windows 中安装和使用 GTK+ 并与 MinGW 一起使用,您可以按照以下步骤操作.我会尽量让它们变得简单,别担心:

Ok, to install and use GTK+ in Windows and use it with MinGW you may follow these steps for example. I'll try to made them the easy, don't worry:

  1. 安装 MinGW,因为您已经完成了,所以我不会详细说明这一步.
  2. 下载 GTK+ 多合一捆绑包(有些东西您可能不使用...但这种方式应该可行).
  3. 解压bundle的内容,你可以在MinGW安装的同一个文件夹中进行,也可以在另一个文件夹中进行,都没有关系.
  4. 启动命令提示符,进入解压缩包的 bin 目录并运行:

  1. Install MinGW, as you've already done it so I wont elaborate this step.
  2. Download the GTK+ all-in-one bundle (there may be things you may not use... but this way should work).
  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.
  4. Launch a command prompt, get to the bin directory where you extracted the bundle and run:

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

它将打印一个编译标志列表,以及要链接到您的项目的库.现在,复制它们并使用以下内容创建一个批处理文件(.bat 或 Windows 命令脚本 .cmd):

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:

设置 VAR=FLAGS
启动cmd

其中 VAR 是变量的名称(例如 GTK),FLAGS 是前一个命令的输出(pkg-config).

Where VAR is a name of a variable (for example GTK) and FLAGS is the output of the previous command (pkg-config).

每当你想编译一些使用 GTK+ 的东西时,双击那个文件,GTK+ 标志将在 VAR 中.你可以这样编译,例如:

Whenever you want to compile something that uses GTK+ double click that file, the GTK+ flags will be in VAR. You may compile this way for example:

gcc foo.c %VAR%

您可能会发现创建用户环境变量并将标志存储在其中更方便,而不是批处理文件,这样您就可以在正常的命令提示符下进行编译.我没有描述这一点,因为这样做的方法因您拥有的 Windows 版本而异.通常,您可以在高级系统属性中找到它.

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. Generally you may find it in advanced system properties.

一旦您对 GTK+ 编程更有信心,您可能不会使用所有包或所有标志,或者以不同的方式对它们重新排序,请使用 makefile 而不是将编译标志和库放在环境变量 ...

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, ...

但现在,这会让你开始.

But by now, this will get you started.

此外,您将动态链接到 GTK+,因此正确的库位于项目的同一目录中,或者在您想要运行它时可以从路径访问.

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.

这篇关于windows下安装gtk和gcc编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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