另外一件事是我想使用两个Go绑定:
https://github.com/mattn/go-gtk和https://github.com/mattn/go-webkit
我正在使用go-webkit示例代码进行测试:
package mainimport ( "os" "github.com/mattn/go-gtk/gtk" "github.com/mattn/go-webkit/webkit")const HTML_STRING = `<DOCTYPE HTML><Meta charset="utf-8"/><style>div { Font-size: 5em }</style><script src="http://code.jquery.com/jquery-latest.Js"></script><script>$(function() { $('#hello1').slIDeDown('slow',function() { $('#hello2').fadeIn() })})</script><div ID="hello1" >Hello</div><div ID="hello2" >世界</div></div>`const MAP_EMbed = `<style> *{ margin : 0; padding : 0; } </style><iframe wIDth="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwIDth="0" src="http://maps.Google.co.jp/maps?f=q&source=s_q&hl=en&geocode=&q=osaka&aq=&sll=34.885931,-115.180664&sspn=29.912003,39.506836&brcurrent=3,0x6000e86b2acc70d7:0xa399ff48811f596d,0&IE=UTF8&hq=&hnear=%E5%A4%A7%E9%98%AA%E5%BA%9C%E5%A4%A7%E9%98%AA%E5%B8%82&ll=34.693738,135.502165&spn=0.471406,0.617294&z=11&output=embed"></iframe>`func main() { gtk.Init(nil) window := gtk.NewWindow(gtk.WINDOW_topLEVEL) window.SetTitle("webkit") window.Connect("destroy",gtk.MainQuit) vBox := gtk.NewVBox(false,1) entry := gtk.NewEntry() entry.SetText("http://golang.org/") vBox.PackStart(entry,false,0) swin := gtk.NewScrolleDWindow(nil,nil) swin.SetPolicy(gtk.POliCY_autoMATIC,gtk.POliCY_autoMATIC) swin.SetShadowType(gtk.SHADOW_IN) webvIEw := webkit.NewWebVIEw() webvIEw.Connect("load-committed",func() { entry.SetText(webvIEw.GetUri()) }) swin.Add(webvIEw) vBox.Add(swin) entry.Connect("activate",func() { webvIEw.LoadUri(entry.GetText()) }) button := gtk.NewbuttonWithLabel("load String") button.Clicked(func() { webvIEw.LoadString("hello Go GTK!","text/plain","utf-8",".") }) vBox.PackStart(button,0) button = gtk.NewbuttonWithLabel("load HTML String") button.Clicked(func() { webvIEw.LoadHTMLString(HTML_STRING,0) button = gtk.NewbuttonWithLabel("Google Maps") button.Clicked(func() { webvIEw.LoadHTMLString(MAP_EMbed,0) window.Add(vBox) window.SetSizeRequest(600,600) window.ShowAll() proxy := os.Getenv("http_PROXY") if len(proxy) > 0 { soup_uri := webkit.soupUri(proxy) webkit.GetDefaultSession().Set("proxy-uri",soup_uri) soup_uri.Free() } entry.Emit("activate") gtk.Main()}
如果我用它编译它,它工作正常
go build
如果我尝试使用其他设置编译它:
GOOS=windows GOARCH=386 go buildGOARCH=386 go build
我收到此错误:
webvIEw.go:5:2: no buildable Go source files in
/home/yeeapple/documents/Coding/Go/Source/src/github.com/mattn/go-gtk/gtkwebvIEw.go:6:2: no buildable Go source files in
/home/yeeapple/documents/Coding/Go/Source/src/github.com/mattn/go-webkit/webkit
我看到的另一件事是在GOPATH目录和pkg文件夹中只有带有* .a文件的“linux_amd64”文件夹.
例如,如果没有其他导入,我可以为其他系统编译Go文件.跨平台编译工作正常:
package mainimport "fmt"func main() { fmt.Printf("hello,world\n")}
版本:
$go versiongo version go1.2.1 linux/amd64$gccgo --versiongccgo (Ubuntu 4.9-20140406-0ubuntu1) 4.9.0 20140405 (experimental) [trunk revision 209157]copyright (C) 2014 Free Software Foundation,Inc.解决方法 使用Go 1.2,交叉编译代码时将禁用cgo功能.这意味着任何包含导入“C”的源文件都不会被编译,这会使许多软件包无法使用.因此,当您简单的“hello world”程序编译时,使用cgo的等效程序将失败:
package main/*#include <stdlib.h>#include <stdio.h>*/import "C"import "unsafe"func main() { hello := C.CString("Hello world") defer C.free(unsafe.Pointer(hello)) C.puts(hello)}
在amd64 linux系统上,如果尝试编译x86,则会出现构建失败:
$GOARCH=386 go build hello.gocan't load package: no buildable Go source files in /...
要使此程序编译,您还需要设置环境变量CGO_ENABLED = 1以手动启用cgo.这将导致它尝试编译程序,但如果您没有安装x86编译器,它仍然会失败.既然你说你使用的是Ubuntu,你可以通过安装gcc-multilib包来实现:
$sudo apt-get install gcc-multilib
安装完成后,您应该能够编译该程序:
$GOARCH=386 CGO_ENABLED=1 go build hello.go$file hellohello: ELF 32-bit LSB executable,Intel 80386,version 1 (SYSV),dynamically linked (uses shared libs),for GNU/linux 2.6.24,BuildID[sha1]=...,not stripped
虽然Ubuntu附带了一个windows交叉编译工具链(在mingw32包中),但你仍然无法编译windows二进制文件:
$GOOS=windows GOARCH=386 CGO_ENABLED=1 go build hello.go go build runtime/cgo: cannot use cgo when compiling for a different operating system
GO 1.3中不再出现此检查,因此您可能会对该版本感到满意.
现在拥有交叉编译器工具链只是战斗的一部分:您还需要为可用的目标体系结构编译的依赖项版本.对于像WebKit这样大的东西来说,这不会是微不足道的,但你可以使用CFLAGS,LDFLAGS和PKG_CONfig_PATH环境变量将Go指向适当的副本.
总结以上是内存溢出为你收集整理的如何在Linux上编译跨平台的Go语言项目?全部内容,希望文章能够帮你解决如何在Linux上编译跨平台的Go语言项目?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)