【问题标题】:hello.go:1:1: illegal character U+0023hello.go:1:1: 非法字符 U+0023
【发布时间】:2016-11-12 14:56:19
【问题描述】:

我正在尝试从 golang in this link 运行 hello world 但是当我运行 go install 时,我收到了这个错误:

hello.go:1:1: illegal character U+0023

这是我的hello.go

package main    
import "fmt"
func main() {
  fmt.Printf("hello, world")
}

我正在使用 Mac OS El Captain 怎么了?

【问题讨论】:

标签: go


【解决方案1】:

您的代码的第一行中有“#”,这是无效的,
查看此测试示例代码:

# just remove this line
package main

import "fmt" 

func main() {
    fmt.Println("Hello World!") 
}

这将给出这个错误:

hello.go:1:1: illegal character U+0023 '#'

但如果你删除包含# 的行,它可以正常工作:

package main

import "fmt"

func main() {
    fmt.Println("Hello World!")
}

您的 IDE 似乎不适用于 Go。见:
https://github.com/visualfc/liteide
https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins
http://www.distilnetworks.com/setup-go-golang-ide-for-mac-os-x/

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,但源代码中没有'#'。我的 LOCALE 设置正确。我的问题是我通过剪切和粘贴从以下位置创建了源代码:

    https://medium.com/@singh.shreya8/how-to-install-go-lang-in-ubuntu-14-04-ubuntu-16-04-ubuntu-18-04-linux-19e4c8aad4b8

    通过删除并重新键入源代码中的双引号解决了该问题。只是为了笑,我尝试从以下位置进行剪切和粘贴:

    https://golang.org/doc/code.html

    并且没有任何问题。去图吧。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多