dongyang9813 2014-04-02 19:19
浏览 1324

Go从命令行运行,但不能从IntelliJ Idea Go运行

Under Mac OS X I did a brew install go. I also downloaded the Go IntelliJ IDE from here

http://go-ide.com/2011/08/09/goide_release_1_0_darwin.html

The following program compiles and runs fine from the command line, but if I use the GO IntelliJ IDE it gives an error:

can't find import: math/rand

import time seems ok, but Duration and time.Millisecond are undefined. If I remove these things and just run the "Hello World version" the program compiles and runs fine.

/**
 * Created by IntelliJ IDEA.
 * User: idf
 * Date: 4/2/14
 * Time: 1:59 PM
 * To change this template use File | Settings | File Templates.
 */

package main

import (
  "fmt"
  "math/rand" /* causes problems */
  "time"
)

func main() {

    sleep := time.Duration(200) /* error: undefined: time.Duration */
    time.Sleep(sleep * time.Millisecond) /* error: undefined: time.Millisecond */


    rand.Intn(1000)

    fmt.Println("Hello World")
}
  • 写回答

1条回答 默认 最新

  • duanmu6752 2014-04-02 21:00
    关注

    Updated:
    You'll need to add your GOROOT and GOPATH: https://github.com/go-lang-plugin-org/go-lang-idea-plugin/blob/master/Missing%20ENV.md

    the exact commands I ran (obviously, your GOPATH and GOROOT will be different):

    launchctl setenv GOPATH /Users/wfreeman/gocode
    launchctl setenv GOROOT /Users/wfreeman/go1.2
    
    评论

报告相同问题?

悬赏问题

  • ¥15 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!