go及gomobile的环境配置这里就不介绍了,直接说aar的生成和使用.
① 设置环境变量GOPATH
GOPATH的值可以有多个,用半角分号间隔,但不能以其结束,设置完成后需要重新做 gomobile init .
执行命令: gomobile bind -target=android hello
会生成一个hello.aar文件
将hello.aar文件放入工程的libs中,并配置build.gradle
在根结点加入:
在dependencies结点下加入依赖:
运行后,结果会输出 Hello, Android and Gopher
Go是一个图灵完备的语言
任何图灵完备的语言理论上都可以用来编译自身.比如c/c◆◆, java, vb, php等等都可以.
至于怎么编译自身的:
用其它语言比如c◆◆实现一个[Go语言编译器-1]
OK,现在有一个Go语言实现的编译器了,最开始那个c◆◆写的编译器没用了,可以扔掉不要了.以后就不停的优化使用这个Go语言实现的自身的编译器就行了.
现代应用支持多平台运行是一件稀松平常的事情,在 Go 语言里面,为了支持应用的多平台部署,给用户提供了方便的配置方式来轻松构建针对不同操作系统和平台的运行文件.
构建标签必须出现在 package 子句之前.为了区分构建标签和包文档的描述注释,构建标签后面应该有一个空行.
构建标签由||, , !运算符以及括号来组合表达.运算符与 Go 中的含义相同.
又如:仅在使用 cgo 时,且仅在 Linux 和 OS X 上构建文件: //go:build cgo (linux || darwin)
除了官方提供的针对不同平台的内置标签,用户也可以使用自定义标签,例如 //go:build prod , 只需要在执行 go build 时显式带上标签名 go build --tags=prod .
想要使文件构建时被忽略,可以使用: //go:build ignore ,其他任何没有被用来定义为标签的词也可以,但"ignore"是约定俗成的.).Go 语言目前支持的系统和架构可以参考 官方文档 .
①.、解压压缩包到go工作目录,如解压到E:\opensource\go\go,解压后的目录结构如下:
E:\opensource\go\go
├─api
├─bin
│ ├─go.exe
│ ├─godoc.exe
│ └─gofmt.exe
├─doc
├─include
├─lib
├─misc
├─pkg
├─src
└─test
修改goenv.bat文件中的GOROOT值为上面的go工作目录后直接双击该bat文件,go编译环境变量即设置完成.
E:\opensource\go\gogo
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
build compile packages and dependencies
clean remove object files
doc run godoc on package sources
env print Go environment information
fix run go tool fix on packages
fmt run gofmt on package sources
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet run go tool vet on packages
Use "go help [command]" for more information about a command.
Additional help topics:
gopath GOPATH environment variable
packages description of package lists
remote remote import path syntax
testflag description of testing flags
testfunc description of testing functions
Use "go help [topic]" for more information about that topic.
直接调用"go build helloworld.go"就生成了"helloworld.exe"可执行程序,运行一下这个程序看到了我们期望的hello,wolrd.
E:\opensource\go\go\testgo build helloworld.go
E:\opensource\go\go\testhelloworld.exe
hello, world
E:\opensource\go\go\test
附一 helloworld.go
// cmpout
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Test that we can do page 1 of the C book.
package main
func main() {
print("hello, world\n")
}
go语言 一个主package包引入同级目录下go文件包编译出错是设置错误造成的,解决方法为:
①.、先使用import "strings"导入strings库.
以上就是土嘎嘎小编为大家整理的go语言编译结果,go相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!