Install the configuration instance under Windows using the go language writer
- 2020-05-30 20:19:58
- OfStack
With linux, google's go language is easy to install and enjoyable to use, and a few lines of code can be powerful.
Now the problem is I want to play under windows...
In fact, windows is no trouble, see below for details.
1. Install go language:
1, install MinGW (https: / / bitbucket org/jpoirier/go_mingw/downloads)
2. Download the source code
Enter C:\MinGW, double-click mintty to open the terminal window;
Perform "hg clone - u release https: / / go googlecode. com hg / / c go" to download the source code;
3. Compile the source code
Execute "cd /c/go/src" into the src directory and execute "./ all.bash "to compile;
4. Set environment variables
After compiling, a base 2 file will be generated under C:\go\bin and "C:\go\bin;" will be added to PATH. ;
2. Write the go code:
File: test go
The code is as follows:
package main
import "fmt"
func main() {
fmt.Println("Test")
}
3. Generate executable files (take my machine as an example, please refer to the official website for details) :
test.go. test.go
Link: 8l-o test.exe test.8
test.exe will output:
Test
4. Generate executable files in batches
If you write a lot of test code, you have to type the command twice every time, which is very inconvenient.
So I decided to write a script that automatically traverses all files ending in ".go "in the current directory, compiles the files to generate the target file, links them to generate the executable, and then deletes the target file. This script is modelled on the previous article (https: / / www. ofstack. com article / 61951. htm) generated in the written Makefile principle, limited functionality, suitable for use in writing test code.
Here's the code (python script) :
'''
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
Ok, that's all, I hope it helped you.