My test program test.go:
package main
import "fmt"
func main() {
fmt.Printf("Hello\n")
}
Running this go run test.go finishes with errors:
# io
pack: cannot open $WORK/io/_obj/_go_.6
# strconv
pack: cannot open $WORK/strconv/_obj/_go_.6
Environment:
go version devel +715674f61ae8 Tue Jan 29 13:34:18 2013 -0800 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/usr/local/google/home/igord/incub/web"
GOROOT="/opt/go"
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
CGO_ENABLED="1"
But I downloaded this version from (featured) RELEASE 1.0.3 on the go site!
Resolved by various in comments, but for the record: installing a binary distribution of Go to a location other than the default requires setting $GOROOT and $GOPATH correctly.
Getting Started: Install the Go tools
Related: what should be the values of GOPATH and GOROOT?
Related
I'm working on go project that implmenting C code !
I can build the project on linux/amd64, and we now that go don't cross compile if we use "IMPORT C".
So i work with XGO that maybe help me to cross compiling for ARM.
i check XGO by cross compiling version of my go project without C code and it's work like cross compil of go.
my environement :
go version go1.13.3 linux/amd64
Go env :
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/opt/go/bin"
GOCACHE="/home/jj/.cache/go-build"
GOENV="/home/jj/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/opt/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/opt/go/src/github.com/brocaar/lora-app-server/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
My project is on =>
/opt/go/src/github.com/brocaar
My package that include c code is on =>
/opt/go/src/github.com/lorawan
the go.mode of my project :
module github.com/brocaar/lora-app-server
go 1.12
replace github.com/brocaar/lorawan => /opt/go/src/github.com/brocaar/lorawan
require (
cloud.google.com/go v0.44.3
github.com/Azure/azure-service-bus-go v0.9.1
github.com/NickBall/go-aes-key-wrap v0.0.0-20170929221519-1c3aa3e4dfc5
github.com/aws/aws-sdk-go v1.19.19
github.com/brocaar/loraserver v0.0.0-20190917115647-c4da45f52f2b
github.com/brocaar/lorawan v0.0.0-20190814113539-8eb2a8d6da09
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/eclipse/paho.mqtt.golang v1.2.0
github.com/elazarl/go-bindata-assetfs v1.0.0
github.com/gofrs/uuid v3.2.0+incompatible
github.com/golang/protobuf v1.3.2
github.com/gomodule/redigo v2.0.0+incompatible
github.com/goreleaser/goreleaser v0.106.0
)
My command to cross-compil is:
xgo -go 1.13.3 --targets=linux/arm-7 /opt/go/src/github.com/brocaar/lora-app-server/cmd/lora-app-server
The result error are :
src/github.com/brocaar/lora-app-server/cmd/lora-app-server
Checking docker installation...
Client:
Version: 18.09.7
API version: 1.39
Go version: go1.10.4
Git commit: 2d0083d
Built: Fri Aug 16 14:19:38 2019
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.09.7
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 2d0083d
Built: Thu Aug 15 15:12:41 2019
OS/Arch: linux/amd64
Experimental: false
Checking for required docker image karalabe/xgo-1.13.3... found.
Cross compiling github.com/brocaar/lora-app-server/cmd/lora-app-server...
Building locally github.com/brocaar/lora-app-server/cmd/lora-app-server...
Bootstrapping linux/arm-7...
go: github.com/brocaar/lorawan#v0.0.0-20190814113539-8eb2a8d6da09: parsing
/opt/go/src/github.com/brocaar/lorawan/go.mod: open /opt/go/src/github.com/brocaar/lorawan/go.mod: no
such file or directory
2019/12/03 16:02:37 Failed to cross compile package: exit status 1.
I really don't now why he say "no such file or directory", because there are go.mod in folder lorawan ! can some one help me ? thanks
I finally find the solution !
firste i install on ubuntu arm-linux-gnueabi-gcc, then i juste i add to my cross-compile-compile command CC like :
env GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabi-gcc go build
It's work fine !
On go version : It prints
go version xgcc (Ubuntu 4.9.1-0ubuntu1) 4.9.1 linux/amd64
My installed version is the latest one and i.e 1.4.2
which got installed from the tar version : go1.4.2.linux-amd64.tar.gz
GO Environmental variables looks exactly like this:
GOARCH="amd64"
GOBIN="/home/user/coding/golang/gocnew/goc/bin"
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/coding/golang/gocnew/goc"
GORACE=""
GOROOT="/home/user/go"
GOTOOLDIR="/home/user/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
I expect go version to be printed as 1.4.2, so how that can be achieved?
Looks like you have two versions of Go installed. One from ubuntu package manager and one you installed from source tar.
To confirm kindly try to remove gccgo :
sudo apt-get remove gccgo
I got the same issue and i fixed it by this way:
Access to go folder: /usr/local/go (The installation folder of go)
Execute these commands:
Added by Go Path
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> ~/.bashrc
And then go to the source folder and check go version:
go version go1.12.2 linux/amd64 it will be displayed the same version in go folder and you can work with go commands.
I installed the Go, then added path requirements to my .bash_profile:
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
I then setup the correct folders:
I also created a projected called tire.
The contents for main.go are simply:
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}
I always get the following error when I try to run go install:
go install: no install location for directory /Users/Daryl/go/src/tire outside GOPATH
Here's what I get when I run go env:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/daryl/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
TERM="dumb"
CC="clang"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fno-common"
CXX="clang++"
CGO_ENABLED="1"
Any help would be appreciated.
When you run go install Go looks for $GOBIN env variable path. Either you need to set your $GOBIN to $GOPATH/bin
$ export GOBIN=$GOPATH/bin
and/or add $GOBIN to your OS search path
$ export PATH=$PATH:$GOBIN
To use the command without getting the error.
The problem was as James Henstridge commented, for some reason there was an issue with my user directory name case. Even though the directory is lowercase, I had to make it capitalized.
This worked:
GOPATH=/Users/Daryl/go
This didn't:
GOPATH=$HOME/go
However, since moving to a rMBP from my iMac, I had no problems whatsoever setting up Go, so, to this day, I'm not sure what was going on, but in that instance the capitalization fixed it.
I had the same problem in Windows 10,
So I set a system variable named GOBIN
with absolute value F:\go\bin.
Then ran go install main.go and everything worked perfectly fine!
I'm attempting to incorporate Heroku's log-shuttle library (https://github.com/heroku/log-shuttle) into a Go project I'm working on. The tool is primarily designed to be run as an independent binary, but I'm hoping to integrate it in a different way in my tool.
So I get the library:
$ go get github.com/heroku/log-shuttle
$ ls $GOPATH/src/github.com/heroku/log-shuttle/
batcher.go Godeps ...
...
which returns successfully. Then I try to import the library:
package myPackage
import (
"github.com/heroku/log-shuttle"
"fmt"
"log"
)
...
Great. But now I go to go build and...
$ go build
# github.com/<my project>
logWriter/log_shuttle_writer.go:5: can't find import: "github.com/heroku/log-shuttle"
I have my GOPATH set correctly (I believe):
$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jeff/go/"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
And the package is installed and built, but it doesn't want to import. As you can see, there are non non-ASCII chars in the package path (though the hyphen is non-alpha-numeric), and I can't find any more info about what could be causing this problem.
Not sure how it would matter, but I am using godep to try to manage my dependencies.
Thanks in advance.
github.com/heroku/log-shuttle is a main package, not an importable library, meaning it's meant to be compiled and run as a binary.
I have a small go program in the directory:
~/gocode/src/github.com/elviejo79/goexample/
When I execute
go install
The program does compile but it leaves the executable in the same directory as the code.
but according to How to Write Go Code the binary should in fact be saved at
~/gocode/bin
this my $GOPATH
$ echo $GOPATH
/home/agarcia/gocode
Cannot reproduce this. Please Enter
$ go env
And verify where your GOBIN points to. For example, at the machine I'm right now, it says
09:01 myname#tux64:~$ go env
GOARCH="amd64"
GOBIN="/home/myname/bin"
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myname"
GOROOT="/home/myname/go"
GOTOOLDIR="/home/myname/go/pkg/tool/linux_amd64"
CGO_ENABLED="1"
09:01 myname#tux64:~$
The go tool should send the binary to $GOBIN. Here it works like that.