dongyao4419 2013-06-08 12:24
浏览 144
已采纳

如何在Win 7上安装gtk

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 ?

  • 写回答

2条回答 默认 最新

  • dongna2498 2013-06-11 11:06
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!