进入IntelliJ IDEA。多个文件和错误未定义:数据 [英] GO in IntelliJ IDEA. Multiple File and Error Undefined: Data

查看:225
本文介绍了进入IntelliJ IDEA。多个文件和错误未定义:数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用IntelliJ IDE Community Edition GO(GoLang)中编写代码。我安装了正确的插件,并安装了所有需要工具来构建应用程序。
我的应用程序由两个以下文件组成。每个都在direcytory ../ EventServer 中。


  • Main.go

  • Data.go

>

如果我想使用函数Run(Ctlr + Shift + F10)从IntelliJ运行项目,并且我得到低于错误

  / usr / lib / go / bin / go build -o/ tmp / Build Main.go and run0go-gcflags-N -l/ my /home/blah/EventServer/Main.go 
#命令行参数
./Main.go:11:undefined:数据

我可以没有任何问题从终端编译代码进入与项目和执行命令direcytory

 :〜/ Pulpit / EventServer $ go build 
./EventServer
Hello
dane w strukturze someone

tree direcytory和文件看起来像

  EventServer $ tree -a 

├──Data.go
├──EventServer
├──EventServer.iml
├──.idea
│├──compiler.xml
│├──copyright b $ b││└──profiles_settings.xml
│├──图书馆
││└──GOPATH__EventServer_.xml
│├──misc。 xml
│├──modules.xml
│├──.name
│├──vcs.xml
│└──workspace.xml
└─ ──Main.go

文件Main.go但不包含所有文件。右命令应该是

  $ go run * .go 

但我不知道我可以在哪里设置。



我还将GOPATH设置为:

  export GOPATH = $ HOME / Pulpit / EventServer 

这也没有帮助

CODE

Main.go

  package main 

import(
fmt



func main( ){

fmt.Println(Hello)
abcd:= Data {someone,1234567}
fmt.Printf(dane w strukturze%s ,abcd.Name)

}



Data.go

 包主


类型数据结构{
姓名字符串
电话字符串

}

系统:LINUX

解决方案

---------------- - - - 解决了 - - - - - - - - - - - - - - - - - - - - - -已解决---------------------

步骤




  • 项目必须是在/ example / MyProject / src / HERE_DIRECTORY_WITH_YOUR_SOURCE_GO_FILE
    sub direcytory src 中的目录中找到很重要

  • 转到运行 - >编辑配置

  • 查找下面的位置





  • 运行种类更改为 Package

  • 位置包装用您的代码编写您的文件夹(Shold be Highlight it is correct )

  • 单击左上角的PLUS图标,然后添加 Go应用程序

  • 应用更改

  • 在右上角的主窗口IDE中您会看到小图标播放






  • 选择早期定义的 Go应用程序我的已打开

  • 点击播放

  • 喜悦:D


I want use IntelliJ IDE Community Edition to write code in GO (GoLang). I instaled right plugin, and instaled all need tools to build application. My application consists with two below file. Each is in direcytory ../EventServer.

  • Main.go
  • Data.go

If I want to run project from IntelliJ using function Run (Ctlr+Shift+F10) and I get below error

/usr/lib/go/bin/go build -o "/tmp/Build Main.go and run0go" -gcflags "-N -l" /my/home/blah/EventServer/Main.go
# command-line-arguments
./Main.go:11: undefined: Data

I can without any problem compiled code from terminal come in to direcytory with project and execution command

:~/Pulpit/EventServer$ go build
./EventServer 
Hello
dane w strukturze someone

tree direcytory and files looks like

EventServer$ tree -a
.
├── Data.go
├── EventServer
├── EventServer.iml
├── .idea
│   ├── compiler.xml
│   ├── copyright
│   │   └── profiles_settings.xml
│   ├── libraries
│   │   └── GOPATH__EventServer_.xml
│   ├── misc.xml
│   ├── modules.xml
│   ├── .name
│   ├── vcs.xml
│   └── workspace.xml
└── Main.go

I suppose that command to run is bad, because compiler trying build program with only one file Main.go but not with all files. Right command should be

$ go run *.go 

But I do not know where Can I set this.

I also set GOPATH to:

export GOPATH=$HOME/Pulpit/EventServer

This also hasn't help

CODE

Main.go

package main

import (
    "fmt"

)

func main() {

    fmt.Println("Hello")
    abcd := Data{"someone" , "1234567"}
    fmt.Printf("dane w strukturze %s ", abcd.Name)

}

And Data.go

package main


type Data struct {
Name string
Phone string

}

SYSTEM: LINUX

解决方案

----------------------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

这篇关于进入IntelliJ IDEA。多个文件和错误未定义:数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆