(待持续更新的文章)
Go现在用的是 gomake来编译程序。大致方法和用make差不多,没去细究和make有啥差别。
简单使用的话,两者可以换用。如: gomake install <==> make install
自己对 Makefile文件不是那么熟悉,所以收集一些简单的Makefile实例。
有些是go src里面带的,有些是从开源Go项目中带的。再次一并感谢之。。
参考资料:
http://golang.org/doc/code.html
编译单个文件:
编译多个文件(一个.go文件生成一个应用程序):
编译包
注意差异: include $(GOROOT)/src/[color=red]Make.pkg[/color]
上面两个文件的使用方法:
# gomake #编译,可以用 make(下同)
# gomake install #安装
# gomake test #单元测试
# gomake clean #清楚本地文件,无法清楚安装文件,即没有make uninstall
cgo文件的编译:
参考:http://cheesesun.blogspot.com/2009/12/basic-cgo.html
参考:http://blog.golang.org/2011/03/c-go-cgo.html
Go现在用的是 gomake来编译程序。大致方法和用make差不多,没去细究和make有啥差别。
简单使用的话,两者可以换用。如: gomake install <==> make install
自己对 Makefile文件不是那么熟悉,所以收集一些简单的Makefile实例。
有些是go src里面带的,有些是从开源Go项目中带的。再次一并感谢之。。
参考资料:
http://golang.org/doc/code.html
编译单个文件:
include $(GOROOT)/src/Make.inc
TARG=helloworld
GOFILES=\
helloworld.go\
include $(GOROOT)/src/Make.cmd
编译多个文件(一个.go文件生成一个应用程序):
include $(GOROOT)/src/Make.inc
ALL=a1 a2
all: $(ALL)
clean:
rm -rf *.[68] $(ALL)
%: %.go
$(GC) $*.go
$(LD) -o $@ $@.$O
编译包
include $(GOROOT)/src/Make.inc
TARG=mypackage
#TARG=mypackage/mysubpackage
GOFILES=\
my1.go\
my2.go\
include $(GOROOT)/src/Make.pkg
注意差异: include $(GOROOT)/src/[color=red]Make.pkg[/color]
上面两个文件的使用方法:
# gomake #编译,可以用 make(下同)
# gomake install #安装
# gomake test #单元测试
# gomake clean #清楚本地文件,无法清楚安装文件,即没有make uninstall
cgo文件的编译:
nclude $(GOROOT)/src/Make.inc
TARG=goblog/rand
CGOFILES=\
rand.go\
include $(GOROOT)/src/Make.pkg
include ../../../src/Make.inc
TARG=runtime/cgotest
CGOFILES=\
align.go\
basic.go\
CGO_OFILES=\
callback_c.o\
OFILES=\
runtime.$O\
include ../../../src/Make.pkg
参考:http://cheesesun.blogspot.com/2009/12/basic-cgo.html
include $(GOROOT)/src/Make.inc
TARG=gocurses
CGOFILES=\
gocurses.go\
#GOFILES=\
# main.go\
CGO_LDFLAGS=-lncurses
CLEANFILES+= $(TARG) main
CGO_OFILES+=
OBJECTS = main.go talkmore.go
include $(GOROOT)/src/Make.pkg
main: install main.go talkmore.go
$(GC) $(OBJECTS)
$(LD) -o $(TARG) main.$O
%: install $(OBJECTS)
$(GC) $(OBJECTS)
$(LD) -o $(TARG) main.$O
参考:http://blog.golang.org/2011/03/c-go-cgo.html