You are not logged in.

#1 2011-10-24 04:17:25

slughappy1
Member
Registered: 2009-03-20
Posts: 75

[Solved] Problem compiling a Go lang program

I have installed go and tried to write a simple program, hello.go.

package main

import "fmt"

func main() {
        fmt.Println("Hello this is frustrating")
}

Whenever I try and compile the program with 'g6 hello.go' I get an error (I am running 64bit btw)
$ 6g hello.go
hello.go:3: can't find import: fmt

I have added the following to my .bashrc aswell and still get that error

export GOROOT=$HOME/Go/src
export GOARCH=amd64
export GOOS=linux
export GOBIN=$HOME/Go/bin
export PATH=$PATH:$GOBIN

Last edited by slughappy1 (2011-10-27 18:09:27)

Offline

#2 2011-10-24 05:23:54

Grinch
Member
Registered: 2010-11-07
Posts: 265

Re: [Solved] Problem compiling a Go lang program

My GOROOT points at the root 'go' directory, you are pointing it at Go/src (you renamed it to an uppercase 'G' I guess), so try pointing GOROOT at $HOME/Go instead.

Offline

#3 2011-10-25 19:33:56

Grinch
Member
Registered: 2010-11-07
Posts: 265

Re: [Solved] Problem compiling a Go lang program

I see that many of the replies disappeared due to the database corruption. Do you still have problems with this?

Offline

#4 2011-10-27 00:05:35

slughappy1
Member
Registered: 2009-03-20
Posts: 75

Re: [Solved] Problem compiling a Go lang program

Grinch wrote:

I see that many of the replies disappeared due to the database corruption. Do you still have problems with this?

As a matter of fact I am still having problems. I installed go from the repo, and I still can't get it to compile. I have a file /etc/profile.d/go.sh with the following in it.

export GOROOT=/usr/lib/go
export GOOS=linux
export GOBIN=/usr/bin

I also edited my ~/.bashrc to include

# For programming language Go
export GOROOT=$HOME/go/src
export GOARCH=amd64
export GOOS=linux
export GOBIN=$HOME/go/bin
export PATH=$PATH:$GOBIN

When I try and write a simple program hello.go it wont compile
$ 6g hello.go
hello.go:3: can't find import: fmt

The file hello.go only has the example code taken from the first page of golang.org

package main

import "fmt"

func main() {
        fmt.Println("Hello")
}

Offline

#5 2011-10-27 00:16:28

denisfalqueto
Member
From: ES, Brazil
Registered: 2006-03-24
Posts: 197

Re: [Solved] Problem compiling a Go lang program

I think your problem is having GOROOT redefined to your home directory. Do you really have a copy of fmt package in there? I believe you should just use what is provided with /etc/profile.d/go.sh. That's what I do and it works.


Satisfied users don't rant, so you'll never know how many of us there are.

Offline

#6 2011-10-27 00:23:33

slughappy1
Member
Registered: 2009-03-20
Posts: 75

Re: [Solved] Problem compiling a Go lang program

denisfalqueto wrote:

I think your problem is having GOROOT redefined to your home directory. Do you really have a copy of fmt package in there? I believe you should just use what is provided with /etc/profile.d/go.sh. That's what I do and it works.

So do I not really need anything in my .bashrc?

Offline

#7 2011-10-27 16:38:53

slughappy1
Member
Registered: 2009-03-20
Posts: 75

Re: [Solved] Problem compiling a Go lang program

Or I suppose I should ask what do I need in my .bashrc relating to Go?

Offline

#8 2011-10-27 18:09:10

slughappy1
Member
Registered: 2009-03-20
Posts: 75

Re: [Solved] Problem compiling a Go lang program

So it turns out I was just mixing things up. I added to my .bashrc file

# For programming language Go
export GOROOT=/usr/lib/go
export GOARCH=amd64
export GOOS=linux
export GOBIN=/usr/bin
export PATH=$PATH:$GOBIN

And now I can compile programs. Thanks for the help.

Offline

#9 2011-10-27 20:34:19

Grinch
Member
Registered: 2010-11-07
Posts: 265

Re: [Solved] Problem compiling a Go lang program

Ok, I didn't install from Arch repo but did a hg pull from the Go weekly releases, hence I don't have a /etc/profile.d/go.sh . Also I've only added GOROOT, GOARCH and GOOS, no need to add GOBIN since the binaries are located under the GOROOT hierarchy.

Offline

#10 2011-10-27 23:57:17

denisfalqueto
Member
From: ES, Brazil
Registered: 2006-03-24
Posts: 197

Re: [Solved] Problem compiling a Go lang program

slughappy1 wrote:

So it turns out I was just mixing things up. I added to my .bashrc file

# For programming language Go
export GOROOT=/usr/lib/go
export GOARCH=amd64
export GOOS=linux
export GOBIN=/usr/bin
export PATH=$PATH:$GOBIN

And now I can compile programs. Thanks for the help.

Sorry for the late answer, but, if you have /etc/profile.d/go.sh, you wouldn't need anything added on .bashrc.

@Grynch: in your case, you will need to add those variables in .bashrc.


Satisfied users don't rant, so you'll never know how many of us there are.

Offline

#11 2011-10-28 02:07:09

Grinch
Member
Registered: 2010-11-07
Posts: 265

Re: [Solved] Problem compiling a Go lang program

denisfalqueto wrote:

@Grynch: in your case, you will need to add those variables in .bashrc.

Yes I know, I've had no problem with Go. What I wrote was in relation to this discussion as it were before the forum database had to be restored resulting in posts gone missing.

Offline

Board footer

Powered by FluxBB