Linux, Google's go language is easy to install, it is also good to use, a few lines of code can achieve very powerful functions.
The problem now is that I want to play under windows ...
In fact, Windows is not trouble, specifically see below.
First, install the Go language:
1, installation MinGW (https://bitbucket.org/jpoirier/go_mingw/downloads)
2, download the source code
Enter C:\MinGW, double-click Mintty to open the terminal window;
The implementation of "HG Clone-u release https://go.googlecode.com/hg//c/go" download source code;
3. Compiling source code
Execute "cd/c/go/src" into the src directory, execute "./all.bash" to compile;
4. Set environment variable
When the compilation is complete, a binary file is generated under C:\go\bin and "C:\go\bin" is added to the path. ;
Second, write go code:
File: Test.go
The code is as follows:
Copy Code code as follows:
Package Main
Import "FMT"
Func Main () {
Fmt. Println ("Test")
}
Iii. Generate executable Files (take my machine as an example, specific reference to the official website documents):
Compiling: 8g-o test.8 test.go
Link: 8l-o test.exe test.8
Execute test.exe, Output:
Test
Iv. batch generation of executable files
If you write a lot of test code, each time you have to enter the command two times, it is very inconvenient.
So I decided to write a script that automatically iterates through all the files in the current directory that end with ". Go", compiles the files, generates the target files, links them to executable files, and deletes the target files. This script is written in the previous article (http://www.jb51.net/article/61951.htm) generated in the makefile principle, the function is limited, suitable for writing test code when used.
Here's the code (Python script):
Copy Code code as follows:
'''
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 '% (cmdcompile,tmpname,file)
Print Strcompile
Os.popen (strcompile) # Compile
Strlink = '%s-o%s '% (cmdlink,name+dstsuffix,tmpname)
Print Strlink
Os.popen (strlink) # link
Os.remove (tmpname) # Remove Temp file
# Search the current directory
Well, that's all, I hope to help you.