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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog