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

如何在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条)

报告相同问题?

悬赏问题

  • ¥15 html5 qrcode 扫描器
  • ¥15 爬取网页信息并保存需要完整代码
  • ¥15 一分十不等功分器阻设计问题,请问这个56Ω怎么得到的
  • ¥15 (标签-matlab)
  • ¥100 求看看这个数学建模,有偿
  • ¥15 深度学习目标检测现在框架加注意力的创新可以投几区?
  • ¥15 PdfiumViewer pdf转图片
  • ¥15 利用Java连接API接口总是出问题
  • ¥15 请教一个关于镜头标定,棋盘格格子大小的问题(畸变测试)
  • ¥15 安装GroudingDINO RuntimeError: Error compiling objects for extension