Golang build cannot find module for path _/mnt/c/XXXXX - go

My system is WSL 2 in Windows 10.
OS: Debian 10 buster
Kernel: x86_64 Linux 4.19.104-microsoft-standard
Shell: zsh 5.7.1
CPU: AMD Ryzen 9 4900HS with Radeon Graphics # 16x 2.994GHz
Golang info:
go version go1.15.2 linux/amd64
GOROOT="/usr/local/go"
GOPATH="/mnt/c/workspace/6.824"
And I met a problem when I build a project by plugin model:
$ go build -buildmode=plugin ../mrapps/wc.go
build command-line-arguments: cannot find module for path _/mnt/c/workspace/6.824/src/mr
It is so strange that "_/mnt"
How can I solve it?
Why has a "_" before the path?
Help me, please.

I would try and use go mod instead of relying on GOPATH
unset GOPATH
cd /mnt/c/workspace/6.824/
go mod init "yourProject"
go build -buildmode=plugin mrapps/wc.go

You are using go mod. And you can try the following command to fix:
cd 6.824
go mod init "6.824-golabs-2020"
# change file src/mrapps/wc.go line9 to `import "6.824-golabs-2020/src/mr"`
cd src
go build -buildmode=plugin mrapps/wc.go
More details about mod you can refer to https://golang.org/ref/mod

Related

What is the message when it is building on Golang?

When I build source on Golang, I saw the warning message, but I couldn't find answer about it.
$ go build --mod=mod -o main main.go
# command-line-arguments
ld: warning: -no_pie is deprecated when targeting new OS versions
specs
version : go version go1.18 darwin/amd64
os : Monterey 12.6
build command : go build --mod=mod -o [binary name] main.go
From GitHub: link
There are a few options:
- wait for the next Go 1.19.x and 1.18.x releases, probably early next month
- build Go from the master branch
- pass -buildmode=pie flag to go build and go test for a workaround
- use older version of the system linker
This seems to be a known issue. See Github for more information.
As a workaround you can pass the -buildmode=pie flag to your go build command.

go 1.18 in google.cloud

Description
I am trying to install a library from a go v1.18 program to access Google Cloud.
Previously, the "go get" command was used, but since version 1.18, it is no longer available.
It seems to use go install, but I get an error when executing the command.
% go install cloud.google.com/go/bigquery
go: 'go install' requires a version when current directory is not in a module
Try 'go install cloud.google.com/go/bigquery#latest' to install the latest version
% go install cloud.google.com/go/bigquery#latest
package cloud.google.com/go/bigquery is not a main package
% go install cloud.google.com/go#latest
package cloud.google.com/go is not a main package
Environments
% go version
go version go1.18 darwin/amd64
% uname -v
Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101.4~15/RELEASE_X86_64
% sw_vers
ProductName: macOS
ProductVersion: 12.3.1
BuildVersion: 21E258
Reference
bigquery package - cloud.google.com/go/bigquery - pkg.go.dev
I tried,
Thank you for your support.
% go mod init cloud.google.com/go
% go get -u cloud.google.com/go/datacatalog
go: added cloud.google.com/go/datacatalog v1.3.0
% go mod tidy
go: downloading google.golang.org/appengine v1.6.7
go: downloading golang.org/x/sys v0.0.0-20220209214540-3681064d5158
% go mod vendor
% go run catalog.go
package command-line-arguments is not a main package
What should I do next ?
Self resolved.
-> change package name "main"
go install is used to install binary programs available on the package. Usually command line tools.
go get, until go1.18, was used to update packages and install programs, they change it by split in several programs
Seems there is nothing to install. Also the main package is not bigquery but cloud.google.com/go
If you want to install a dependency, if you are using vendorized modules you can do
$ go get -u cloud.google.com/go/bigquery
$ go mod tidy
$ go mod vendor
If not, you may try it by running go mod init first

Unable to Install Go-Ipfs from source

I'm trying to Build IPFS from Source on windows 10.
Previously i installed it from source.It was working fine. But i needed the latest source so i started again from the scratch. because i edited some parts in the source.
I followed instructions on https://github.com/ipfs/go-ipfs/blob/master/docs/windows.md.
I received following error on executing following commands.
code
cd %GOPATH%\src\github.com\ipfs\go-ipfs
make install
Error
go version go1.12.6 windows/amd64
bin/check_go_version 1.12
go install -asmflags=all=-trimpath="D:\GO_WORKSPACE" -gcflags=all=-trimpath="D:\GO_WORKSPACE" -ldflags="-X "github.com/ipfs/go-ipfs".CurrentCommit=810cb607e-dirty" ./cmd/ipfs
# github.com/ipfs/go-ipfs/plugin/loader
plugin\loader\preload.go:11:2: undefined: pluginipldgit
plugin\loader\preload.go:12:2: undefined: pluginbadgerds
plugin\loader\preload.go:13:2: undefined: pluginflatfs
plugin\loader\preload.go:14:2: undefined: pluginlevelds
make: *** [cmd/ipfs/Rules.mk:37: cmd/ipfs-install] Error 2
I tried Adding this plugins in to preload.go file under src\github.com\ipfs\go-ipfs\plugin\loader directory.
exisiting code on preload.go.
import (
"github.com/ipfs/go-ipfs/plugin"
)
i added after the issue
import (
"github.com/ipfs/go-ipfs/plugin"
pluginipldgit "github.com/ipfs/go-ipfs/plugin/plugins/git"
pluginbadgerds "github.com/ipfs/go-ipfs/plugin/plugins/git"
pluginflatfs "github.com/ipfs/go-ipfs/plugin/plugins/git"
pluginlevelds "github.com/ipfs/go-ipfs/plugin/plugins/git"
)
so after i added this lines result is success.
Executed command
make install
Result
go version go1.12.6 windows/amd64
bin/check_go_version 1.12
go install -asmflags=all=-trimpath="D:\GO_WORKSPACE" -gcflags=all=-trimpath="D:\GO_WORKSPACE" -ldflags="-X "github.com/ipfs/go-ipfs".CurrentCommit=810cb607e-dirty" ./cmd/ipfs
Then i tried to start the ipfs using following command
ipfs daemon
Error
Initializing daemon...
go-ipfs version: 0.4.22-dev-810cb607e-dirty
Repo version: 7
System version: amd64/windows
Golang version: go1.12.6
Error: unknown datastore type: flatfs
Can someone help me configure the IPFS from source.
Thanks in advance.
I solved this problem by following method. not sure this will be a good solution or not. any way i could solve the issue.
I'm posting this as a answer. so it will be useful to everyone who has the same issue.
1) Deleted go-ipfs folder inside the "%GO_WORKSPACE% / .... / ipfs" folder.
2) Git clone the go ipfs repo manually on the same location.
3) go inside go-ipfs folder.
4) execute install command.
make install
Done on Windows.
Save IPFS (kubo) to some folder inside %GOPATH% (I cloned https://github.com/ipfs/kubo) to folder %GOPATH%\kubo
Important cd %GOPATH%\kubo\cmd\ipfs\
go install
ipfs.exe was placed in %GOPATH%\bin
I launched it as daemon - works.
BTW: GOROOT is defined and path to go is included in PATH

Error while running make command using Fabric 1.0.6 after all the 15 steps

I am installing fabric in a custom path $HOME//gopath/src/github.com/hyperledger/fabric using the make command but after installing all the 15 steps, I am getting the following error
Step 15/15 : LABEL org.hyperledger.fabric.version=1.0.2 org.hyperledger.fabric.base.version=0.3.2
---> Running in ed05a67810db
Removing intermediate container ed05a67810db
---> 99b4b0b28957
Successfully built 99b4b0b28957
Successfully tagged hyperledger/fabric-javaenv:latest
docker tag hyperledger/fabric-javaenv hyperledger/fabric-javaenv:x86_64-1.0.2
build/bin/peer
CGO_CFLAGS=" " GOBIN=/root/gopath/src/github.com/hyperledger/fabric/build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.0.2 -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.2 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/peer
go build github.com/hyperledger/fabric/vendor/github.com/miekg/pkcs11: invalid flag in #cgo LDFLAGS: -Wl,--no-as-needed
Makefile:227: recipe for target 'build/bin/peer' failed
make: *** [build/bin/peer] Error 1
Docker version 17.12.0-ce, build c97c6d6
docker-compose version 1.18.0, build 8dd22a9
go version go1.9.4 linux/amd64
OS : Ubuntu 16.04
I have set the following path also
$ mkdir $HOME/gopath
$ export GOPATH=$HOME/gopath
$ export GOROOT=$HOME/go
$ export PATH=$PATH:$GOROOT/bin
Jira Link: https://jira.hyperledger.org/browse/FAB-2218 which I have already done
It is a known issue in go 1.9.4:
https://github.com/golang/go/issues/23739
While go people are fixing it, you can manually whitelist the flags before starting make:
$ export CGO_LDFLAGS_ALLOW='-Wl,--no-as-needed'
$ make
Alternatively you can just downgrade to go 1.9.3
as far as I know you don't need to build the fabric itself.
You just need to have sources in the gopath, as your chaincode will need this, when you are building your chaincode for the blockchain itself.
In addition you will probably also need to install the fabric-ca for your chaincode to build successfully, if you use the certificate-stuff.
This is sufficient to check if you installed fabric correctly:
cd $GOPATH/src/github.com/hyperledger/fabric
make unit-test
Keep going if this works.
I found this confusing at first as well ;)
I'd assume you switch to golang 1.9.4 or greater hence I belive this actually related to following issue, to solve it you need to update vendor dependencies:
govendor fetch github.com/hyperledger/fabric/vendor/github.com/miekg/pkcs11
Next continue to build binaries and run tests.

Installing Go Language

I'm trying to install Go language, but at the end, I got these errors (I won't copy all because are a lot of lines):
$>=========== fixedbugs/bug359.go
> BUG: errchk: fixedbugs/bug359.go:19: missing expected error: '"unexported field"'
> errchk: fixedbugs/bug359.go:25: missing expected error: '"a redeclared"'
> errchk: unmatched error messages:
> ==================================================
> fixedbugs/bug359.go:12: import /home/anju/go/pkg/linux_386/container/list.a:
object is [linux 386 release.r56 9441] expected [linux 386 release.r60.3 10088+]
> ==================================================
0 known bugs; 78 unexpected bugs; test output differs
FAILED
I've followed step by step the instructions, but always I get the same results. I edited my .bashrc with ne next lines:
export GOROOT=$HOME/go
export GOARCH=386
export GOOS=linux
export GOBIN=$HOME/bin
export PATH=$GOBIN:$PATH
But when I execute the command uname -a, I get these:
$Linux Anju 2.6.32-35-generic #78-Ubuntu SMP Tue Oct 11 15:27:15 UTC 2011 i686 GNU/Linux.
So, GOARCH=386 it's ok or maybe I should use another value?
Thanks for the attention and excuse me my bad english.
The standard default for $GOBIN is:
export GOBIN=$GOROOT/bin
You probably have multiple versions of Go installed. For example, [linux 386 release.r56 9441] and [linux 386 release.r60.3 10088+]. Therefore, you probably have multiple versions of Go binaries such as 8g, perhaps in both $HOME/bin and $GOROOT/bin ($HOME/go/bin).
i found a tutorial but i am not comfortable with terminal so can't figure it. http://www.kelvinwong.ca/2009/11/12/installing-google-go-on-mac-os-x-leopard/

Resources