JeanP
JeanP

Reputation: 507

GoLand IDE not correctly compiling. How to setup correct paths?

I am trying to setup GoLand correctly to be able to use it with Go.

I'm trying to run the follow simple HelloWorld go project.

package HelloWorldProject


import "fmt"

func main(){
    fmt.Printf("Hello")

    fmt.Printf("1+1 = ", 1+1)

}

This is my console's results:

GOROOT=/usr/local/Cellar/go/1.10/libexec #gosetup
GOPATH=/Users/jeanmac/go #gosetup
/usr/local/Cellar/go/1.10/libexec/bin/go build -i -o /private/var/folders/r5/rfwd1cqd4kv8cmh5gh_qxpvm0000gn/T/___Hello /Users/jeanmac/go/src/github.com/jpere547/HelloWorldProject/Hello.go #gosetup

Compilation finished with exit code 0

I am on Mac OS and I installed Go using Brew.

Results of brew info go:

go: stable 1.10 (bottled), HEAD
Open source programming language to build simple/reliable/efficient software
https://golang.org
/usr/local/Cellar/go/1.10 (8,150 files, 336.9MB) *
  Poured from bottle on 2018-03-22 at 19:38:29
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/go.rb
==> Requirements
Required: macOS >= 10.8 ✔
==> Options
--without-cgo
    Build without cgo (also disables race detector)
--without-race
    Build without race detector
--HEAD
    Install HEAD version
==> Caveats
A valid GOPATH is required to use the `go get` command.
If $GOPATH is not specified, $HOME/go will be used by default:
  https://golang.org/doc/code.html#GOPATH

You may wish to add the GOROOT-based install location to your PATH:
  export PATH=$PATH:/usr/local/opt/go/libexec/bin

The GoLand configurations is below:
GOROOT GOROOT

GOPATH GOPATH

Upvotes: 5

Views: 10872

Answers (4)

priyantanu gupta
priyantanu gupta

Reputation: 1

There is an option in configuration to run after build. I think you are missing to set it's configuration.Steps: 1. Go to Run 2. Select "Edit configuration" 3. Select the check-box below output directory field specifying "Run after build".

Upvotes: 0

李冬平
李冬平

Reputation: 1

you can try to change the package name instead of main

Upvotes: 0

dlsniper
dlsniper

Reputation: 7477

It looks like you are trying to run a non main package. Specifically, instead of package HelloWorldProject, you should use package main. After that the IDE will be able to not only build but also run the package.

Upvotes: 10

Plawan Rath
Plawan Rath

Reputation: 42

When you do go build something.go or go isntall something.go that only builds/installs the go package to give you an executable. You will need to run that executable.

The easiest way to run simple Golang programs is simply use go run something.go that will run your go file.

As long as your GOPATH is correctly set it should work

Upvotes: 0

Related Questions