简体   繁体   English

如何在Win 7上安装gtk

[英]How to set up gtk for go on Win 7

I would like to create a small GUI with go on windows 7 32bit. 我想在Windows 7 32bit上创建一个小的GUI。 This is what I did: 这是我所做的:

To check the correct installation, I typed gcc in the command prompt. 要检查正确的安装,我在命令提示符下键入了gcc It returned the error message realgcc: no input file , so it seems like gcc is installed correctly. 它返回了错误消息realgcc:没有输入文件 ,因此似乎gcc已正确安装。 Then I tried to run gtk-demo . 然后我尝试运行gtk-demo It worked, too 它也起作用

  • My go installation is tested and runs fine. 我的go安装已经过测试,可以正常运行。 I've already developed a small server with it. 我已经用它开发了一个小型服务器。 GOROOT and GOPATH are both set correctly. GOROOT和GOPATH均已正确设置。
  • To install go-gtk, I used go get github.com/mattn/go-gtk/gtk 要安装go-gtk,我用go get github.com/mattn/go-gtk/gtk

The installation finished with a lot of warnings. 安装结束时出现了很多警告。

C:\\Users\\lhk>go get github.com/mattn/go-gtk/gtk C:\\ Users \\ lhk>获取github.com/mattn/go-gtk/gtk

# github.com/mattn/go-gtk/glib #github.com/mattn/go-gtk/glib

realgcc.exe: warning: '-xc' after last input file has no effect realgcc.exe:警告:最后输入文件后的“ -xc”无效

realgcc.exe: no input files realgcc.exe:没有输入文件

# github.com/mattn/go-gtk/gdk #github.com/mattn/go-gtk/gdk

realgcc.exe: warning: '-xc' after last input file has no effect realgcc.exe:警告:最后输入文件后的“ -xc”无效

realgcc.exe: no input files realgcc.exe:没有输入文件

# github.com/mattn/go-gtk/pango #github.com/mattn/go-gtk/pango

realgcc.exe: warning: '-xc' after last input file has no effect realgcc.exe:警告:最后输入文件后的“ -xc”无效

realgcc.exe: no input files realgcc.exe:没有输入文件

C:\\Users\\lhk> C:\\ Users \\ lhk>

To test the installation of go-gtk, I used the sample code from here: http://mattn.github.io/go-gtk/ . 为了测试go-gtk的安装,我使用了以下示例代码: http : //mattn.github.io/go-gtk/ I tried to run this code with go run but it terminated with an error message: 我尝试通过go run运行此代码,但是它终止并显示错误消息:

# github.com/mattn/go-gtk/glib #github.com/mattn/go-gtk/glib
realgcc.exe: warning: '-xc' after last input file has no effect realgcc.exe:警告:最后输入文件后的“ -xc”无效
realgcc.exe: no input files realgcc.exe:没有输入文件
# github.com/mattn/go-gtk/gdk #github.com/mattn/go-gtk/gdk
realgcc.exe: warning: '-xc' after last input file has no effect realgcc.exe:警告:最后输入文件后的“ -xc”无效
realgcc.exe: no input files realgcc.exe:没有输入文件
# github.com/mattn/go-gtk/pango #github.com/mattn/go-gtk/pango
realgcc.exe: warning: '-xc' after last input file has no effect realgcc.exe:警告:最后输入文件后的“ -xc”无效
realgcc.exe: no input files realgcc.exe:没有输入文件
exit status 2 退出状态2

What did I do wrong ? 我做错什么了 ? How do I set up gtk for use with go correctly ? 如何设置gtk以正确使用go?

Update 更新资料

mb0 on the Go IRC channel was very helpful and pointed me to this https://groups.google.com/forum/?fromgroups#!topic/golang-nuts/GwbkQREiTZI Go IRC频道上的mb0很有帮助,并向我指出了这个https://groups.google.com/forum/?fromgroups#!topic/golang-nuts/GwbkQREiTZI

The creator of go-gtk apparently got go-gtk to work on win32. go-gtk的创建者显然让go-gtk在win32上工作。 He didn't use go get. 他没有使用go get。 Instead he cloned the github repo into the src folder on his GOPATH and used the mingw compiler shell to call mingw32-make. 相反,他将github存储库克隆到他的GOPATH上的src文件夹中,并使用mingw编译器外壳调用mingw32-make。

I did the exact same thing: Cloned the repo and called mingw32-make. 我做了完全一样的事情:克隆了仓库,然后叫mingw32-make。 It starts to compile but fails with the error message: 它开始编译,但失败,并显示错误消息:

# pkg-config --cflags gtksourceview-2.0 #pkg-config --cflags gtksourceview-2.0

Package gtksourceview-2.0 was not found in the pkg-config search path. 在pkg-config搜索路径中找不到软件包gtksourceview-2.0。

Perhaps you should add the directory containing "gtksourceview-2.0.pc" 也许您应该添加包含“ gtksourceview-2.0.pc”的目录

to the PKG_CONFIG_PATH environment variable 到PKG_CONFIG_PATH环境变量

No package "gtksourceview-2.0" found exit status 找不到包“ gtksourceview-2.0”的退出状态

1 mingw32-make: * [all] Error 2 1 mingw32-make: * [全部]错误2

This actually gives some specific advice. 这实际上给出了一些具体建议。 Apparently there's a package config utility and it doesn't find an important package. 显然有一个软件包配置实用程序,它找不到重要的软件包。 Unfortunately I'm at a loss how to solve this. 不幸的是,我无所适从。 I checked the gtk website and found this article on pkg-config http://www.gtk.org/api/2.6/gtk/gtk-compiling.html 我检查了gtk网站,并在pkg-config http://www.gtk.org/api/2.6/gtk/gtk-compiling.html上找到了这篇文章

It seems to me that pkg-config is responsible for configurating the package imports. 在我看来,pkg-config负责配置软件包的导入。 Therefore I'm hesitant to just create the PKG_CONFIG_PATH variable myself since I don't know where it should point. 因此,我不愿意自己创建PKG_CONFIG_PATH变量,因为我不知道它应该指向何处。 I just tried to run the to shell commands in my mingw shell: pkg-config --cflags gtk+-2.0 and pkg-config --libs gtk+-2.0 . 我只是尝试在mingw shell中运行to shell命令: pkg-config --cflags gtk+-2.0pkg-config --libs gtk+-2.0 The first seems to display a list of include paths and the second just prints the available libraries. 第一个似乎显示包含路径的列表,第二个似乎仅打印可用的库。 There are pango, cairo, gobject, pixbuf and many others but definitely no library named something like gtksourceview. 有pango,cairo,gobject,pixbuf等许多工具,但绝对没有像gtksourceview这样的库。

My guess is that I don't have this lib on my machine. 我的猜测是我的机器上没有这个库。 Which confuses me, since I downloaded and unzipped the all in one bundle which was supposed to satisfy all dependencies. 这让我感到困惑,因为我将所有文件下载并解压缩为一个可以满足所有依赖关系的软件包。

What can I do to solce this problem ? 我该怎么办才能解决这个问题?

It finally works. 终于可以了。 Here's a step by step guide to getting gtk to work on windows 32bit with go. 这是逐步指导,使gtk在go的32位Windows上工作。

  • Install Mingw and Msys 安装Mingw和Msys
  • Download the gtk all-in-one bundle from here http://www.gtk.org/download/win32.php 从此处http://www.gtk.org/download/win32.php下载gtk多合一捆绑包
  • Unzip it to C:\\GTK . 将其解压缩到C:\\ GTK。 I've heard that the name is important. 我听说这个名字很重要。 Personally I can't think of a reason why, but you might want to keep this in mind as a possible error source. 就我个人而言,我想不出原因,但是您可能要记住这是可能的错误来源。
  • Add the bin folder to your path. 将bin文件夹添加到您的路径。 Now you should be able to run gtk-demo from your shell. 现在,您应该可以从Shell中运行gtk-demo了。

The gtk website says that the all-in-one bundle contains both the gtk+ stack and 3rd party dependencies . gtk网站表示,多合一捆绑包同时包含gtk +堆栈和3rd party依赖项。 But in order to compile go-gtk on windows, you will need to install additional libraries. 但是为了在Windows上编译go-gtk,您将需要安装其他库。

You need gtksourceview and libxml. 您需要gtksourceview和libxml。 These can be found here: http://ftp.gnome.org/pub/gnome/binaries/win32/gtksourceview/2.10/ and here: http://ftp.gnome.org/pub/GNOME/binaries/win32/dependencies/ 这些可以在这里找到: http : //ftp.gnome.org/pub/gnome/binaries/win32/gtksourceview/2.10/以及这里: http : //ftp.gnome.org/pub/GNOME/binaries/win32/dependencies /

The download will be a zipped file containing various folders. 下载将是一个包含各种文件夹的压缩文件。 You need to unzip the folders and copy them into C:\\GTK . 您需要解压缩文件夹并将其复制到C:\\ GTK。 Windows will ask you if you want to integrate them into the existing ones. Windows会询问您是否要将它们集成到现有的。 Yes you do. 是的你是。 Now you have downloaded all the dependencies. 现在,您已经下载了所有依赖项。

  • Open the Mingw shell and navigate into the go-gtk folder 打开Mingw shell并导航到go-gtk文件夹
  • Call "pkg-config --cflags gtk+-2.0" 调用“ pkg-config --cflags gtk + -2.0”
  • Call "pkg-config --libs gtk+-2.0" 调用“ pkg-config --libs gtk + -2.0”
  • Call mingw32-make 致电mingw32-make

The compilation should work fine. 编译应该可以正常工作。 If there are errors and mingw complains about missing libraries you should be able to install them just as you installed gtksourceview and libxml. 如果有错误,并且mingw抱怨缺少库,您应该能够像安装gtksourceview和libxml一样安装它们。

Now to test go-gtk 现在测试go-gtk

  • Create a new folder in your go src directory. 在go src目录中创建一个新文件夹。 I named it "gtktest" 我将其命名为“ gtktest”
  • Create a new .go file. 创建一个新的.go文件。
  • Copy the sample code from here: http://mattn.github.io/go-gtk/ 从此处复制示例代码: http : //mattn.github.io/go-gtk/
  • use go build to create an exe 使用go build创建一个exe

I hope this helps you to use go and gtk on windows. 我希望这可以帮助您在Windows上使用go和gtk。

I have being trying to get a GUI framework run on GO/Windows, and I finally managed to do it following your instructions. 我一直试图在GO / Windows上运行GUI框架,但最终我按照您的指示进行了操作。

I have just a few additions: 我只有几个补充:

  • I added "C:\\GTK\\bin" to the PATH, instead of "C:\\GTK" 我在路径中添加了“ C:\\ GTK \\ bin”,而不是“ C:\\ GTK”
  • I had to add an third dependency: pthreads 我必须添加第三个依赖项:pthreads
  • To download the right dependency: Take everytime the file which contains "dev" in its file name 要下载正确的依赖项:每次获取文件名中包含“ dev”的文件
  • The mingw-console can be found on C:\\MinGW\\msys\\1.0\\msys.bat 可以在C:\\ MinGW \\ msys \\ 1.0 \\ msys.bat中找到mingw控制台

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

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