- 时间:2020-06-08 21:07 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:Windows下使用go语言写程序安装配置实例
linux下,google的go语言安装起来很方便,用起来也很爽,几行代码就可以实现很强大的功能。
现在的问题是我想在windows下玩……
其实windows下也不麻烦,具体见下文。
[b]一、安装go语言:
[/b]1、安装MinGW([url=https://bitbucket.org/jpoirier/go_mingw/downloads]https://bitbucket.org/jpoirier/go_mingw/downloads[/url])
2、下载源码
进入C:\MinGW,双击mintty开启终端窗口;
执行"hg clone -u release [url=https://go.googlecode.com/hg/]https://go.googlecode.com/hg/[/url] /c/go"下载源码;
3、编译源码
执行"cd /c/go/src"进入src目录,执行"./all.bash"进行编译;
4、设置环境变量
编译完成后,会在C:\go\bin下生成二进制文件,在PATH中加入"C:\go\bin;";
[b]二、写go代码:[/b]
文件:test.go
代码如下:
[url=http://www.1sucai.cn/article/61951.htm]http://www.1sucai.cn/article/61951.htm[/url])中生成Makefile的原理写的,功能有限,适合写测试代码的时候用。
这里是代码(python脚本):
'''
File : compileGo.py
Author : Mike
E-Mail : Mike_Zhang@live.com
'''
import os
srcSuffix = '.go'
dstSuffix = '.exe'
cmdCompile = "8g"
cmdLink = "8l"
fList = []
for dirPath,dirNames,fileNames in os.walk('.'):
for file in fileNames:
name,extension = os.path.splitext(file)
if extension == srcSuffix :
fList.append(name)
tmpName = name + '.8' # temp file
strCompile = '%s -o %s %s ' % (cmdCompile,tmpName,file)
print strCompile
os.popen(strCompile) # compile
strLink = '%s -o %s %s' % (cmdLink,name+dstSuffix,tmpName)
print strLink
os.popen(strLink) # link
os.remove(tmpName) # remove temp file
break # only search the current directory
好,就这些了,希望对你有帮助。