如何在Windows 7上设置Go的GTK

huangapple go评论96阅读模式
英文:

How to set up gtk for go on Win 7

问题

我想在Windows 7 32位上使用go创建一个小的GUI。这是我所做的:

  • 我安装了MinGw。
  • 我从这里下载了gtk+的全套捆绑包:http://www.gtk.org/download/win32.php,并将其添加到我的PATH变量中。

为了检查正确的安装,我在命令提示符中输入了gcc。它返回了错误消息realgcc: no input file,所以看起来gcc安装正确。然后我尝试运行gtk-demo,它也可以工作。

  • 我的go安装经过测试,运行良好。我已经用它开发了一个小型服务器。GOROOT和GOPATH都设置正确。
  • 为了安装go-gtk,我使用了go get github.com/mattn/go-gtk/gtk

安装过程中出现了很多警告。

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

github.com/mattn/go-gtk/glib

realgcc.exe: warning: '-x c' after last input file has no effect

realgcc.exe: no input files

github.com/mattn/go-gtk/gdk

realgcc.exe: warning: '-x c' after last input file has no effect

realgcc.exe: no input files

github.com/mattn/go-gtk/pango

realgcc.exe: warning: '-x c' after last input file has no effect

realgcc.exe: no input files

C:\Users\lhk>

为了测试go-gtk的安装,我使用了这里的示例代码:http://mattn.github.io/go-gtk/。我尝试用go run运行这段代码,但它以错误消息终止:

github.com/mattn/go-gtk/glib

realgcc.exe: warning: '-x c' after last input file has no effect
realgcc.exe: no input files

github.com/mattn/go-gtk/gdk
realgcc.exe: warning: '-x c' after last
input file has no effect
realgcc.exe: no input files

github.com/mattn/go-gtk/pango
realgcc.exe: warning: '-x c' after last
input file has no effect
realgcc.exe: no input files
exit status 2

我做错了什么?如何正确设置go与gtk一起使用?

更新

Go IRC频道上的mb0非常有帮助,他指向了这个链接https://groups.google.com/forum/?fromgroups#!topic/golang-nuts/GwbkQREiTZI

go-gtk的创建者显然在win32上使go-gtk工作。他没有使用go get,而是将github仓库克隆到了他的GOPATH的src文件夹中,并使用mingw编译器shell调用mingw32-make。

我做了完全相同的事情:克隆了仓库并调用了mingw32-make。它开始编译,但失败并显示错误消息:

pkg-config --cflags gtksourceview-2.0

Package gtksourceview-2.0 was not found in the pkg-config search path.

Perhaps you should add the directory containing "gtksourceview-2.0.pc"

to the PKG_CONFIG_PATH environment variable

No package "gtksourceview-2.0" found exit status

1 mingw32-make: *** [all] Error 2

这实际上给出了一些具体的建议。显然有一个包配置工具,它找不到一个重要的包。不幸的是,我不知道如何解决这个问题。我查看了gtk网站,并在pkg-config上找到了这篇文章http://www.gtk.org/api/2.6/gtk/gtk-compiling.html

在我看来,pkg-config负责配置包导入。因此,我不敢自己创建PKG_CONFIG_PATH变量,因为我不知道它应该指向哪里。我刚刚尝试在我的mingw shell中运行两个shell命令:pkg-config --cflags gtk+-2.0pkg-config --libs gtk+-2.0。第一个似乎显示了一系列的包含路径,第二个只打印了可用的库。有pango、cairo、gobject、pixbuf和许多其他库,但绝对没有名为gtksourceview的库。

我猜我在我的机器上没有这个库。这让我困惑,因为我下载并解压了满足所有依赖关系的全套捆绑包。

我该怎么解决这个问题?

英文:

I would like to create a small GUI with go on windows 7 32bit. This is what I did:

To check the correct installation, I typed gcc in the command prompt. It returned the error message realgcc: no input file, so it seems like gcc is installed correctly. Then I tried to run gtk-demo. It worked, too

  • My go installation is tested and runs fine. I've already developed a small server with it. GOROOT and GOPATH are both set correctly.
  • To install go-gtk, I used 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
>
> # github.com/mattn/go-gtk/glib

> realgcc.exe: warning: '-x c' after last input file has no effect

> realgcc.exe: no input files

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

>realgcc.exe: warning: '-x c' after last input file has no effect

>realgcc.exe: no input files

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

>realgcc.exe: warning: '-x c' after last input file has no effect

>realgcc.exe: no input files

C:\Users\lhk>

To test the installation of go-gtk, I used the sample code from here: http://mattn.github.io/go-gtk/ . I tried to run this code with go run but it terminated with an error message:

> # github.com/mattn/go-gtk/glib
realgcc.exe: warning: '-x c' after last input file has no effect
realgcc.exe: no input files

> github.com/mattn/go-gtk/gdk
realgcc.exe: warning: '-x c' after last
> input file has no effect
realgcc.exe: no input files

> github.com/mattn/go-gtk/pango
realgcc.exe: warning: '-x c' after last
> input file has no effect
realgcc.exe: no input files
exit status 2

What did I do wrong ? How do I set up gtk for use with go correctly ?

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

The creator of go-gtk apparently got go-gtk to work on win32. He didn't use 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.

I did the exact same thing: Cloned the repo and called mingw32-make. It starts to compile but fails with the error message:

> # pkg-config --cflags gtksourceview-2.0

> Package gtksourceview-2.0 was not found in the pkg-config search path.

> Perhaps you should add the directory containing "gtksourceview-2.0.pc"

> to the PKG_CONFIG_PATH environment variable

> No package "gtksourceview-2.0" found exit status

> 1 mingw32-make: *** [all] Error 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

It seems to me that pkg-config is responsible for configurating the package imports. Therefore I'm hesitant to just create the PKG_CONFIG_PATH variable myself since I don't know where it should point. 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. 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.

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 ?

答案1

得分: 2

它终于可以工作了。
这是一个逐步指南,教你如何在Windows 32位系统上使用go来使用gtk。

  • 安装Mingw和Msys
  • 从这里下载gtk的全套包:http://www.gtk.org/download/win32.php
  • 将其解压到C:\GTK。我听说名称很重要。个人来说,我想不出为什么,但你可能要记住这一点,因为它可能是一个潜在的错误来源。
  • 将bin文件夹添加到你的路径中。现在你应该能够从命令行中运行gtk-demo了。

gtk的网站上说,全套包包含了gtk+堆栈和第三方依赖项。但是为了在Windows上编译go-gtk,你需要安装额外的库。

你需要gtksourceview和libxml。它们可以在这里找到:http://ftp.gnome.org/pub/gnome/binaries/win32/gtksourceview/2.10/
和这里:http://ftp.gnome.org/pub/GNOME/binaries/win32/dependencies/

下载将是一个包含各种文件夹的压缩文件。你需要解压这些文件夹并将它们复制到C:\GTK。Windows会问你是否要将它们集成到现有的文件夹中。是的,你要这样做。现在你已经下载了所有的依赖项。

  • 打开Mingw shell并导航到go-gtk文件夹
  • 调用"pkg-config --cflags gtk+-2.0"
  • 调用"pkg-config --libs gtk+-2.0"
  • 调用mingw32-make

编译应该能够正常工作。如果有错误,并且Mingw抱怨缺少库,你应该能够像安装gtksourceview和libxml一样安装它们。

现在来测试go-gtk吧。

  • 在你的go src目录中创建一个新的文件夹。我将其命名为"gtktest"。
  • 创建一个新的.go文件。
  • 从这里复制示例代码:http://mattn.github.io/go-gtk/
  • 使用go build创建一个可执行文件

希望这能帮助你在Windows上使用go和gtk。

英文:

It finally works.
Here's a step by step guide to getting gtk to work on windows 32bit with go.

  • Install Mingw and Msys
  • Download the gtk all-in-one bundle from here http://www.gtk.org/download/win32.php
  • Unzip it to 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. Now you should be able to run gtk-demo from your shell.

The gtk website says that the all-in-one bundle contains both the gtk+ stack and 3rd party dependencies . But in order to compile go-gtk on windows, you will need to install additional libraries.

You need gtksourceview and 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/

The download will be a zipped file containing various folders. You need to unzip the folders and copy them into C:\GTK . Windows will ask you if you want to integrate them into the existing ones. Yes you do. Now you have downloaded all the dependencies.

  • Open the Mingw shell and navigate into the go-gtk folder
  • Call "pkg-config --cflags gtk+-2.0"
  • Call "pkg-config --libs gtk+-2.0"
  • Call 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.

Now to test go-gtk

  • Create a new folder in your go src directory. I named it "gtktest"
  • Create a new .go file.
  • Copy the sample code from here: http://mattn.github.io/go-gtk/
  • use go build to create an exe

I hope this helps you to use go and gtk on windows.

答案2

得分: 0

我一直在尝试在GO/Windows上运行一个GUI框架,最终按照您的指示成功做到了。

我只有几个补充:

  • 我将"C:\GTK\bin"添加到了PATH中,而不是"C:\GTK"
  • 我不得不添加第三个依赖项:pthreads
  • 下载正确的依赖项:每次选择文件名中包含"dev"的文件
  • mingw-console可以在C:\MinGW\msys\1.0\msys.bat中找到
英文:

I have being trying to get a GUI framework run on GO/Windows, and I finally managed to do it following your instructions.

I have just a few additions:

  • I added "C:\GTK\bin" to the PATH, instead of "C:\GTK"
  • I had to add an third dependency: pthreads
  • To download the right dependency: Take everytime the file which contains "dev" in its file name
  • The mingw-console can be found on C:\MinGW\msys\1.0\msys.bat

huangapple
  • 本文由 发表于 2013年6月8日 20:24:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/16999498.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定