This is a creation in Article, where the information may have evolved or changed.
Linux, Google's go language is easy to install, it is also very cool, a few lines of code can achieve a very powerful function.
Now the problem is I want to play under windows ...
In fact, Windows is not troublesome, 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;
Execute "HG clone-u release https://go.googlecode.com/hg//c/go" download source code;
3. Compiling the source code
Execute "cd/c/go/src" into src directory, execute "./all.bash" to compile;
4. Setting Environment variables
After compiling, the binaries are generated under C:\go\bin, and the "C:\go\bin" is added to the path. ;
Second, write the Go code:
Files: test.go
The code is as follows:
Package Main
Import "FMT"
Func Main () {
Fmt. Println ("Test")
}
Third, generate executable files (in my machine, for example, refer to the official website documentation):
Compilation: 8g-o test.8 Test.go
Link: 8l-o test.exe test.8
Executing the test.exe will output:
Test
Iv. batch generation of executable files
If you write a lot of test code, every time you have to input two times command, feeling very inconvenient.
So I decided to write a script that would automatically traverse all the files in the current directory that end with ". Go", compile the file, generate the target file, link to the executable file, and then delete the target file. This script is written in the previous article (http://www.cnblogs.com/MikeZhang/archive/2012/01/17/2324567.html) that generated the makefile principle, limited functionality, Suitable for writing test code.
Here is the code (Python script):
1 '''
2 File:compileGo.py
3 Author:mike
4 e-mail:mike_zhang@live.com
5 '''
6 ImportOs
7
8Srcsuffix ='. Go'
9Dstsuffix ='. EXE'
TenCmdcompile ="8g"
OneCmdlink ="8l"
A
-Flist = []
- forDirpath,dirnames,filenamesinchOs.walk ('.'):
the forFileinchFileNames:
-name,extension = os.path.splitext (file)
- ifExtension = = Srcsuffix:
-Flist.append (name)
+Tmpname = name +'. 8' #temp File
-Strcompile ='%s-o%s%s'% (Cmdcompile,tmpname,file)
+ PrintStrcompile
AOs.popen (Strcompile)#Compile
atStrlink ='%s-o%s%s'% (Cmdlink,name+dstsuffix,tmpname)
- PrintStrlink
-Os.popen (Strlink)#Link
-Os.remove (Tmpname)#Remove Temp file
- Break #Only search for the current directory
All right, that's it, I hope it helps you.