Hello World syntax error
When I try to compile the example from the front page of the go language website with the 6g compiler, I get this error:
hello.go:5: syntax error near "<string>"
I search on Google reveals that a few people have experienced this, but I have found no solution. The answer always seems to be: "It's works for me, you must do something wrong".
I've found a description of the problem that dates back 5 months, so I suspect it's not a problem with the par开发者_C百科ticular build of go that I'm using. Besides, I've tried pulling a newer version, and the problem persists.
The source code in question:
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}
Btw, I'm saving the source code as UTF-8 with LFs for newlines. It shouldn't be a text encoding issue. I've also tried with different strings not containing "exotic" characters
Try "which 6g". You might be picking up an old build. At least that was my case. I had an old 2009 build in my path. After fixing the environment it worked.
Your special characters in there might cause conflicts with the compiler. Try to save this code in multiple ways using notepad (ANSI, UTF-8), and see whether the compiler will take any of them.
Problems like this are typical when there's an encoding issue.
If you're on Windows, an editor like Notepad++ can convert between many encoding formats, so I'd suggest converting your source to UTF-8 without BOM and then recompile.
If you're on Linux, there's a guide available showing you how to determine and change a document's encoding.
精彩评论