Running a go run main.go I get a strange error message:
danilo#lm ~/godev/src/quick $ go run main.go
command-line-arguments
/usr/lib/go-1.6/pkg/tool/linux_amd64/link: cannot open file /usr/lib/go-1.6/pkg/linux_amd64/github.com/valyala/quicktemplate.a: open /usr/lib/go-1.6/pkg/linux_amd64/github.com/valyala/quicktemplate.a: no such file or directory`
Here is my environment:
Linux Mint 18
GOLANG ENV:
danilo#lm ~/godev/src/quick $ go env
GOARCH="amd64"
GOBIN="/home/danilo/godev/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/danilo/godev"
GORACE=""
GOROOT="/usr/lib/go-1.6"
GOTOOLDIR="/usr/lib/go-1.6/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
My $GOPATH tree:
.(godev)
├── bin
│ └── qtc
├── pkg
│ └── linux_amd64
│ └── github.com
│ └── valyala
│ ├── bytebufferpool.a
│ └── quicktemplate.a
└── src
├── github.com
│ └── valyala
│ ├── bytebufferpool
│ │ ├── ...
│ └── quicktemplate
│ ├── ...
└── quick
├── main.go
└── templates
├── hello.qtpl
└── hello.qtpl.go
It seems like to miss the pkg folder in my workspace where the static libraries are stored!
Am I right?
Sorry, I solved. The main.go code was:
package main
import (
"fmt"
"./templates"
)
func main() {
fmt.Printf("%s\n", templates.Hello("Foo"))
fmt.Printf("%s\n", templates.Hello("Bar"))
}
so I missed to use absolute path in the import section:
package main
import (
"fmt"
"quick/templates"
)
func main() {
fmt.Printf("%s\n", templates.Hello("Foo"))
fmt.Printf("%s\n", templates.Hello("Bar"))
}
Related
Using Arch Linux and I have Ctag 5.8 installed.
My Go project has this structure:
.
├── apply
│ └── apply.go
├── calculate
│ └── calculate.go
├── coupon.sqlite3
├── Godeps
│ ├── Godeps.json
│ └── Readme
├── main.go
├── Makefile
├── models
│ ├── cupom.go
│ ├── errorMessage.go
│ └── product.go
├── ping
│ └── ping.go
├── README.md
├── routes
│ └── routes.go
├── tags
├── tests
│ ├── apply_test.go
│ ├── calculate_test.go
│ ├── config.go
│ ├── coupon.sqlite3
│ └── fixtures
│ └── calculate.go
Running the command ctags -R or ctags -R . I have a tags file generated but with this content only.
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert#users.sourceforge.net/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.8 //
Running the same command on other project generate the tags file correctly.
You have Exuberant Ctags installed, which does not support Go out of the box (http://ctags.sourceforge.net/languages.html).
There are a bunch of different alternative programs or ways to add it to your existing ctags:
https://go-wise.blogspot.ca/2011/09/using-ctags-with-go.html
https://github.com/eapache/starscope
https://github.com/jstemmer/gotags
http://ctags.sourceforge.net/EXTENDING.html
I have QtCreator project named UePOSCommClient, which is some GUI applications, which is dependent on another QtCreator project, named UePOSCommProtocol, which is implementation of communications protocol betwwen UePOSCommClient and some Server app. Here is UePOSCommClient projects directory hirerachy:
uePOSCommClient/
├── build
│ └── x64
│ ├── debug
│ │ ├── main.o
│ │ ├── Makefile
│ │ ├── moc_uemainwindow.cpp
│ │ ├── moc_uemainwindow.o
│ │ ├── uemainwindow.o
│ │ └── uePOSCommClient
│ └── release
├── main.cpp
├── uemainwindow.cpp
├── uemainwindow.h
├── uePOSCommClient.pro
└── uePOSCommClient.pro.user
and here is UePOSCommProtocol's project's directoty hirerachy:
uePOSCommProtocol/
├── build
│ └── x64
│ ├── debug
│ │ ├── libuePOSCommProtocol.so -> libuePOSCommProtocol.so.1.0.0
│ │ ├── libuePOSCommProtocol.so.1 -> libuePOSCommProtocol.so.1.0.0
│ │ ├── libuePOSCommProtocol.so.1.0 -> libuePOSCommProtocol.so.1.0.0
│ │ ├── libuePOSCommProtocol.so.1.0.0
│ │ ├── Makefile
│ │ ├── moc_uemessageheader.cpp
│ │ ├── moc_uemessageheader.o
│ │ ├── moc_uemessagerequest.cpp
│ │ ├── moc_uemessagerequest.o
│ │ ├── moc_ueposcommprotocol.cpp
│ │ ├── moc_ueposcommprotocol.o
│ │ ├── uemessageheader.o
│ │ ├── uemessagerequest.o
│ │ └── ueposcommprotocol.o
│ └── release
│ ├── libuePOSCommProtocol.so -> libuePOSCommProtocol.so.1.0.0
│ ├── libuePOSCommProtocol.so.1 -> libuePOSCommProtocol.so.1.0.0
│ ├── libuePOSCommProtocol.so.1.0 -> libuePOSCommProtocol.so.1.0.0
│ ├── libuePOSCommProtocol.so.1.0.0
│ ├── Makefile
│ ├── moc_uemessageheader.cpp
│ ├── moc_uemessageheader.o
│ ├── moc_uemessagerequest.cpp
│ ├── moc_uemessagerequest.o
│ ├── moc_ueposcommprotocol.cpp
│ ├── moc_ueposcommprotocol.o
│ ├── uemessageheader.o
│ ├── uemessagerequest.o
│ └── ueposcommprotocol.o
├── net
│ └── comm_protocol
│ ├── uemessageheader.cpp
│ ├── uemessageheader.h
│ ├── uemessagerequest.cpp
│ ├── uemessagerequest.h
│ └── ueprotocolcommands.h
├── settings
│ └── uedefaults.h
├── ueposcommprotocol.cpp
├── ueposcommprotocol_global.h
├── ueposcommprotocol.h
├── uePOSCommProtocol.pro
└── uePOSCommProtocol.pro.user
Now, all works fine, the project UePOSCommClient compiles without errors, and runs without problems. However, in UePOSCommProtocol project, I have following #include statement:
#include "../../../../../../../../../home/users/Projects/uePOSCommProtocol/settings/uedefaults.h"
which is absolute path to uedefaults.h file. I am aware this is a bad practice and therefore I've replaced upper #include with:
#include "settings/uedefaults.h"
After doing so now I get No such file or directory error:
In file included from ../../../../uePOSCommProtocol/ueposcommprotocol.h:7:0,
from ../../../uemainwindow.h:11,
from ../../../main.cpp:3:
../../../../uePOSCommProtocol/net/comm_protocol/uemessagerequest.h:9:33: fatal error: settings/uedefaults.h: No such file or directory
#include "settings/uedefaults.h"
^
compilation terminated.
make: *** [main.o] Error 1
14:43:03: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project uePOSCommClient (kit: Desktop Qt 5.6.0 GCC 64bit)
When executing step "Make"
Both projects reside in /home/user/Projects directory and why am I getting this error?
P.S.: I am using Qt 5.6.0 for Linux (64bit) with QtCreator 3.6.1 on Ubuntu Linux 14.04 LTS (64bit).
I am trying to use a shared library in go-lang, I am following this blog post: http://blog.ralch.com/tutorial/golang-sharing-libraries/
But when I hit build I get back an error:
simo#simo:~/gopath$ go build -linkshared -o app effe/prova
src/effe/prova/prova.go:3:8: cannot find package "libmath" in any of:
/usr/local/go/src/libmath (from $GOROOT)
/home/simo/gopath/src/libmath (from $GOPATH)
I am pretty new to go, so I will show also my environment...
simo#simo:~/gopath$ pwd
/home/simo/gopath
simo#simo:~/gopath$ echo $GOPATH
/home/simo/gopath
simo#simo:~/gopath$ tree
.
├── pkg
│ └── linux_amd64_dynlink
│ ├── effe
│ │ ├── libmath.a
│ │ └── libmath.shlibname
│ └── libeffe-libmath.so
└── src
└── effe
├── libmath
│ └── libmath.go
└── prova
└── prova.go
7 directories, 5 files
simo#simo:~/gopath$ cat src/effe/libmath/libmath.go
// filename: libmath.go
package libmath
func Sum(x, y int) int {
return x + y
}
simo#simo:~/gopath$ cat src/effe/prova/prova.go
package main
import "libmath"
import "fmt"
func main() {
fmt.Printf("5 op 10 => %d", libmath.Sum(5, 10))
}
simo#simo:~/gopath$ go install -buildmode=shared -linkshared effe/libmath
simo#simo:~/gopath$ go build -linkshared -o app effe/prova
src/effe/prova/prova.go:3:8: cannot find package "libmath" in any of:
/usr/local/go/src/libmath (from $GOROOT)
/home/simo/gopath/src/libmath (from $GOPATH)
What am I doing wrong ?
The import path for "libmath" is "effe/libmath".
Try to get your build working in the standard build mode before experimenting with more complicated build and execution modes.
I'm a beginner in Go and I would like to use the Revel web framework.
I installed: Git; Mercurial and even: Bazaar and CVS.
I checked my environment variables. I set environment variable GOPATH to D:\Go and added D:\Go\bin to PATH.But I still get these errors when I go get The Revel Framework (go get github.com/revel/revel)
**
package golang.org/x/net/websocket: unrecognized import path "golang.org/x/net/websocket"
package gopkg.in/fsnotify.v1: unrecognized import path "gopkg.in/fsnotify.v1"**
For instalation of GO into your home folder you need this environment variables:
.
├── bin
├── go (GO)
└── src
├── revel.project
│ ├── app
│ │ ├── controllers
│ │ ├── models
│ │ ├── routes
│ │ ├── tmp
│ │ └── views
│ │ ├── admin
│ │ ├── App
│ │ ├── errors
│ │ └── users
│ ├── conf
│ ├── messages
│ ├── public
│ │ ├── css
│ │ │ └── administrator
│ │ ├── img
│ │ ├── js
│ │ └── uploads
│ │ └── 1
│ ├── resources
│ ├── scripts
│ ├── test-results
│ └── tests
├── code.google.com
├── github.com
│ ├── revel
│ │ ├── cmd
│ │ ├── modules
│ │ └── revel
run this in your prompt path or modify if your folders are differents.
export GOARCH=amd64
export GOPATH=~/go
export GOBIN=~/go/go/bin
export GOROOT=~/go/go
export PATH=$PATH:$GOPATH/go/bin
export GOTOOLDIR=~/go/go/pkg/tool/linux_amd64
export CC="gcc"
export GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
export CXX=g++
export CGO_ENABLED=1
Where ~ is the name of you personal folder in the system (Bash Gnu Linux)
Problem
I haven't been able to find a solution to this by looking at related questions. I can't tell what makes my Go environment different from the canonical setup.
go env returns
GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="386"
GOCHAR="8"
GOOS="linux"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_386"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread"
CGO_ENABLED="1"
tree $GOPATH returns
/home/USER/go
├── bin
├── pkg
│ └── linux_386
│ └── bitbucket.org
│ └── USER-NAME
│ └── PROJECT
│ └── my_package.a
└── src
└── bitbucket.org
└── USER-NAME
└── PROJECT
├── main
│ ├── main.go
└── my_package
└── my_package.go
(ALL-CAPS are substitutions)
main.go contains
package main
import (
"bitbucket.org/USER-NAME/PROJECT/my_package"
)
func main() {
my_package.Foo()
}
Calling go build in the main directory returns import "my_package": cannot find package
Volker pointed out that go env should have returned a GOPATH entry as well. The source of the env command corroborates that. However, running echo $GOPATH in bash or os.Getenv("GOPATH") in Go both return \home\USER\go. I'm not sure why the same isn't returned by go env.
Solution
I was running Go 1.0 when I was having this issue. The problem disappeared when I upgraded to Go 1.2.1.
You have a directory called main. This won't work. Change it.
Structure it like $GOPATH/src/bitbucket.com/youruser name/yourpackagename/{main.go, otherthing.go, otherpackagedirectory}.
"package main" doesn't have to be in it's own sub folder: it inherits the name of your Bitbucket project (username/myprojectname).
You did not set (or export) GOPATH. GOPATH Is much more important than GOROOT (at least in newe Go versions).