标签:
假设有个Go语言的工程myproject,目录结构如下
myproject
+-- src
|-- myapp
| +-- myapp.go
+-- mylib
+-- logger.go
其中mylib目录是一个lib库,myapp是一个应用,其中引用了mylib库。
下面是logger.go和myapp.go程序代码
logger.go
package mylib
import "fmt"
func Print(msg string) {
fmt.Print(msg)
}
myapp.go
package main
import (
"mylib"
)
func main() {
mylib.Print("Hello World!\n")
}
export GOPATH=/home/kongxx/test/golang/myproject
cd /home/kongxx/test/golang/myproject
go install mylib
go install myapp
下面是运行编译打包之后的目录结构,其中
* pkg 目录是生成的库目录
* bin 目录是生成的可运行程序目录
myproject
|-- bin
| +-- myapp
|-- pkg
| +-- linux_amd64
| +-- mylib.a
+-- src
|-- myapp
| +-- myapp.go
+-- mylib
+-- logger.go
运行bin/myapp即可。
转载请以链接形式标明本文地址
本文地址:http://blog.csdn.net/kongxx/article/details/50444492
标签:
原文地址:http://blog.csdn.net/kongxx/article/details/50444492