GO in IntelliJ IDEA. Multiple File and Error Undefined: Data

前端 未结 4 2096
你的背包
你的背包 2021-02-02 17:25

I want use IntelliJ IDE Community Edition to write code in GO (GoLang). I instaled right plugin, and instaled all need tools to build applicati

相关标签:
4条回答
  • 2021-02-02 17:49

    ----------------------SOLVED-------------------------------------------SOLVED---------------------

    Steps

    • Project must be found in directory for/example/MyProject/src/HERE_DIRECTORY_WITH_YOUR_SOURCE_GO_FILE sub direcytory src is important
    • Go to Run --> Edit Configurations
    • Find below position

    • Change Run Kind to Package
    • In Position Package write Your folder with Your code (Shold be Highlight it is correct)
    • Click On PLUS icon in left top corner, and Add Go Application
    • Apply changes
    • In the right top corner main window IDE You see small icon Play

    • Chose early defined Go Application my is Unamed
    • Click Play
    • An Joy :D
    0 讨论(0)
  • 2021-02-02 17:53

    Sarp Kaya, just follow Mbded steps. Additional step is, ensure that your additional GOPATH should be there.

    For example, this is our ~/.profile GOPATH

    export GOPATH=$HOME/lib/Go:$HOME/Development/Go
    

    The first path used by go get processes etc, while your active go development directory goes to the next path.

    According to our config, the RightApp exact path should be $HOME/Development/Go/src/RightApp.

    0 讨论(0)
  • 2021-02-02 17:58

    Let say you are having a project with src/ sub directory and two .go files inside: hello.go and typetest.go and both defines the same package "main". One of them (hello.go) also implements func main().

    To make it compile as whole you need to make sure two things are configured properly: GOPATH and Run/Debug configuration.

    Open the Project Libraries/GOPATH settings:

    For Gogland

    File -> Settings -> Go

    For Intellij IDEA

    File -> Settings -> Languages & Frameworks -> Go -> Go Libraries

    Makes sure the GOPATH for the project looks something like that:

    GOPATH settings

    Next, open Run -> Edit Configurations and make sure your configuration looks similar to this:

    Run/Debug configuration

    0 讨论(0)
  • 2021-02-02 18:11

    You can add second file (in your case Data.go) as Go tool arguments field in Run/Debug Configurations. I read about this here: https://github.com/go-lang-plugin-org/go-lang-idea-plugin/issues/2013 near the end of discussion. Example below (I used 2 files HelGo.go and aaa.go) worked for me:

    Go Run Configuration with 2 files

    Intellij objected in these 2 files were in different folders, and so both of them has to be same package (main). On the other side I couldn't make any advises on this page work at all.

    0 讨论(0)
提交回复
热议问题