简体   繁体   English

设置GTK +以在MinGW中显示GUI

[英]Set up GTK+ to display GUIs in MinGW

This is a university assignment to make GUI's in C - I am using windows 7 这是大学的任务,以在C中制作GUI-我正在使用Windows 7

I have followed several tutorials and nothing seems to work. 我遵循了一些教程,但似乎没有任何效果。 To give you an idea of what I have done 让您知道我做了什么

I have gtk, msys and minGW all installed. 我已经安装了gtk,msys和minGW。

I believe I have all the necessary cygwin packages (is this relevant??) 我相信我拥有所有必要的cygwin软件包(这相关吗?)

When I try to compile a C program with gtk stuff included in cygwin just to see if I have installed whatever I needed to I get 当我尝试使用cygwin中包含的gtk东西编译C程序时,只是为了查看是否已安装所需的软件

$ gcc base.c -o base `gtk-config --cflags --libs`

Sunny@Sunny-Brain ~
$ ./base

Gtk-WARNING **: cannot open display:

I am not sure what this mean. 我不知道这是什么意思。 It seems to compile and then fails on running. 它似乎编译,然后运行失败。

I have used https://mail.gnome.org/archives/gtk-list/2008-May/msg00116.html as the method of setting gtk up but it asks me to unzip and untar a pixman file which doesnt work. 我已经使用https://mail.gnome.org/archives/gtk-list/2008-May/msg00116.html作为设置gtk的方法,但它要求我解压缩并解压缩不起作用的pixman文件。 I downloaded gtk as a bundle and it is in my C: drive eager to make GUI's for me. 我以捆绑形式下载了gtk,它在我的C:驱动器中,急于为我制作GUI。

In case it helps - I have a pixman-0.26.2 and inside, a pixman-0.26.2.tar.gz - also in my C: drive. 如果有帮助-我的C:驱动器中也有一个pixman-0.26.2,内部有一个pixman-0.26.2.tar.gz。

At this point I am willing to try anything. 在这一点上,我愿意尝试任何事情。

You seem to have installed the X11 version of GTK using Cygwin. 您似乎已经使用Cygwin安装了XK版本的GTK。 The X11 version of GTK requires an X server to be running in order to use it. GTK的X11版本要求运行X服务器才能使用它。 The error message is telling you that the environment variable telling GTK which X server to connect to is not set. 该错误消息告诉您未设置告诉GTK要连接到哪个X服务器的环境变量。 That probably means that no X server is running. 这可能意味着没有X服务器正在运行。

I recommend that you install the Windows version of GTK (which does not require an X server and also uses a native Windows look and feel by default) and compile using that and MinGW. 我建议您安装Windows版本的GTK(它不需要X服务器,并且默认情况下也使用本机Windows外观),并使用该版本和MinGW进行编译。 You shouldn't need to use Cygwin at all. 您根本不需要使用Cygwin。

I found the solution. 我找到了解决方案。

I already had cygwin installed. 我已经安装了cygwin。 I used mingw and msys because: 我使用mingw和msys是因为:

1) I am a newb 1)我是新手

2) Being a newb I went online, found a few tutorials on setting up GTK and just naively followed them. 2)作为一名新手,我上线了,找到了一些关于设置GTK的教程,只是天真地跟随了他们。

If you have cygwin installed already you do not need mingw or msys. 如果已经安装了cygwin,则不需要mingw或msys。 But you do need the following: 但是您确实需要以下条件:

a) The appropriate cygwin packages installed: When using the cygwin installer, do not use the default install. a)已安装适当的cygwin软件包:使用cygwin安装程序时,请勿使用默认安装。 Either find out what packages you specifically need or install all of them and delete as appropriate if you know what you are doing. 找出您特别需要的软件包,或者安装所有软件包,并在知道要做什么的情况下适当删除它们。

b) In order to display GUI's, there needs to be an environmental path variable for displaying it. b)为了显示GUI,需要有一个用于显示它的环境路径变量。 Set it using this: 使用此设置:

export DISPLAY=:0

then check it using 然后使用

echo $display

it should echo - 它应该回声-

:0

check that you can display a GUI using: 使用以下命令检查是否可以显示GUI:

xclock&

If this displays a clock, then you are set to do some GTK tutorials. 如果显示时钟,那么您将准备进行一些GTK教程。

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

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