Step 1 Set your environment variables:
E.G. On my windows box I set:
(look in $GOROOT/pkg for applicable architecture and OS Options)
Step 2 Create a source file in the go language (a go source file):
Use a text editor or write a golang source file:
Sample Hello World GO Language source file:
________________________SOURCE FILE________________________________________
package main
import fmt "fmt" // Package implementing formatted I/O.
func main() {
fmt.Printf("Hello, world; from go to ecocrypt.blogspot.com \n")
}
________________________END SOURCE_________________________________________
Save this file to helloworld.go or any filename of your choice.
Step 3 Compile
prompt % 8g helloworld.go
Step 4 Link
prompt % 8l helloworld.go
Step 5 Run the newly created executable:
prompt % 8.out
Hello, world; from go to ecocrypt.blogspot.com
Congratulate Yourself! You have created and run Hello World in Go.
You should now have a Go compiler successfully installed on your computer.
SOME COMMON ERRORS:
Using the wrong executable to compile go source:
prompt % 8c.exe helloworld.go
helloworld.go:1 not a function
helloworld.go:1 syntax error, last name: main
This Error is caused because you are trying to compile a go source file with a c compiler. 8c is a c compiler embedded in the go distribution package.
Using the wrong architecture or os settings:
prompt % 8g.exe helloworld.go
helloworld.go:3: can't find import: fmt
Make sure you have set the go environment variables correctly:
Determining the GOOS, and GOARCH can be tricky, you will have to look in:
$GOROOT/pkg/
and there will be a directory of format $GOOS_$ARCH
E.G. On my windows box I set:
No comments:
Post a Comment
All comments are greatly appreciated! Comments will be moderated, and usually appear within 1 day. If you like a post, instead of saying you like it, vote for it or digg it (links provided). If there is any ERROR, PLEASE Comment I strive for good quality complete content.