go build cannot find appdynamics go-sdk package - go

go build is unable to find the 'appdynamics' package, even though the GOPATH is properly set. I downloaded the package, copied it onto the GOPATH: ~/go/src/appdynamics and ran go install appdynamics. I am using go v.1.10 on Ubuntu 18.4.
Visual Studio Code is able see the package and code completion works within the IDE. However, running go get -fix -v appdynamics produces the following error:
warning: no cgo types: exit status 1
warning: no cgo types: exit status 1
I have also tested this using the github.com/appdynamics namespace per the appdynamics go-sdk instructions. Also, I am aware of all the other go build 'cannot find package' questions on S.O.

Related

How do you read debug VCS version info from a Go 1.18 binary?

I'm trying to read version control information from my Go binaries, but the build info doesn't seem to contain any VCS info.
From the Go 1.18 release notes:
The go command now embeds version control information in binaries. It includes the currently checked-out revision, commit time, and a flag indicating whether edited or untracked files are present. Version control information is embedded if the go command is invoked in a directory within a Git, Mercurial, Fossil, or Bazaar repository, and the main package and its containing main module are in the same repository. This information may be omitted using the flag -buildvcs=false.
Sample program:
package main
import (
"fmt"
"runtime/debug"
)
func main() {
if bi, ok := debug.ReadBuildInfo(); ok {
fmt.Printf("%+v\n", bi)
}
}
Using this code, here's my output:
go go1.18
path [redacted]
mod [redacted] (devel)
dep [redacted] v1.2.3
build -compiler=gc
build CGO_ENABLED=1
build CGO_CFLAGS=
build CGO_CPPFLAGS=
build CGO_CXXFLAGS=
build CGO_LDFLAGS=
build GOARCH=amd64
build GOOS=windows
build GOAMD64=v1
I expected to see this included, but didn't:
build vcs=git
build vcs.revision=[sha]
build vcs.time=2022-03-28T03:11:12Z
build vcs.modified=true
I'm running the go command from the root directory of a git repo, and the repo has commits. The program I'm building is in a subdirectory of the repo.
I have tried a number of different variations for building the binary, but none of them worked:
go run client/main.go
go build -o client.exe client/main.go && ./client.exe
go build -o client.exe client/main.go && ./client.exe
go build -o client.exe -buildvcs=true client/main.go && ./client.exe
To be clear, the program builds and executes, but doesn't contain embedded VCS information.
I also tried using go version -m client.exe to see if that could read something that the binary couldn't read about itself, but the results were the same.
I'm using the first release of Go 1.18, so -buildvcs should still default to true as far as I know. I saw on the issue tracker that a future minor release will likely change the default to -buildvcs=auto.
As far as I can tell, both conditions listed in the release notes (go is invoked in a directory inside a git repo, and the main package is in the same repo) should both be satisfied when building from the project root. What might I be doing wrong?
I believe my issue was due to incorrect usage of the go run and go build commands. I was running and building against file patterns because I had originally tried go build client from the project root and gotten an error of "package is not in GOROOT", so I was building file patterns instead without understanding the difference (because it compiled and ran successfully).
I found that if I change directories into the subdirectory with the program I want to build (rather than build from the project root) the build command will embed the version information as expected.
e.g.:
cd client/ && go build
As #JimB pointed out in the comments, the go command is meant to operate on packages.
When building from the project root, this is the command I should have been using that will properly embed VCS version info inside the binary:
go build ./client
This behavior around relative path names is still confusing behavior to me, since I had expected go build client and go build ./client to be equivalent (which they are apparently not). Behavior around relative paths seems to be documented here: https://pkg.go.dev/cmd/go#go1.18#hdr-Relative_import_paths

VS Code Go: $GOPATH/go.mod exists but should not

I'm trying to use the Go features of VS Code (like 'Go to definition') in a package with a go.mod. However, if I go into the repository's main directory (with the go.mod) and code ., I get this error:
Error loading workspace folders (expected 1, got 0) failed to load view for file:///Users/kurt/Documents/http-enrollment-portal: err: exit status 1: stderr: $GOPATH/go.mod exists but should not
I've read that I might have to update the gopls language server, so I pressed Cmd + Shift + P and selected "Go: Install/Update Tools" and selected gopls; however, this gives me the same error:
go.toolsGopath setting is not set. Using GOPATH /Users/kurt/Documents/http-enrollment-portal:/Users/kurt/go
Installing 1 tool at /Users/kurt/Documents/http-enrollment-portal/bin in module mode.
gopls
Installing golang.org/x/tools/gopls FAILED
1 tools failed to install.
gopls:
Error: Command failed: /usr/local/opt/go#1.12/bin/go get -v golang.org/x/tools/gopls
$GOPATH/go.mod exists but should not
$GOPATH/go.mod exists but should not
The strange thing is that 'Go to definition' does work in other repositories. I suppose a possible solution is to set the go.toolsGopath?
go env -w GOPATH=
GOPATH and Modules
this link
When using modules, GOPATH is no longer used for resolving imports. However, it is still used to store downloaded source code (in GOPATH/pkg/mod) and compiled commands (in GOPATH/bin).
I had a similar issue. So to explain I am using https://www.mongodb.com/blog/post/quick-start-golang-mongodb-starting-and-setup
To try Mongodb with Go. In VS Code I first installed go mod init quickstart
Then I used go get go.mongodb.org/mongo-driver and got the error $GOPATH/go.mod exists but should not.
I had previously set my GOPATH according to https://www.freecodecamp.org/news/setting-up-go-programming-language-on-windows-f02c8c14e2f/ (see Phase 3 on this page).
I went into my Windows Environment Variables and deleted my GOPATH. On the Windows 10 start menu go to System then Advanced system settings under the Advanced tab click the Environment Variables button and I deleted my GOPATH variable.
Next back in VS Code I again try go get go.mongodb.org/mongo-driver and it works.
you have to go to the folder where you created your go project and delete the go.mod file after you create another file with the command : go mod init nameproject on your command prompt (power

facing issues while running chaincode locally using docker

i m getting below error while running learn-chaincode example on my local system please provide me the suitable solution for the mentioned error
$ go build
# github.com/hyperledger/fabric/vendor/github.com/miekg/pkcs11
exec: "gcc": executable file not found in %PATH%
Looks like the Fabric team introduced "nopkcs11" tag to bypass the problem - https://jira.hyperledger.org/browse/FAB-2854
I used the following command to build my chain code:
go build -tags nopkcs11
My understanding is that the Learn Chaincode example from https://github.com/IBM-Blockchain/learn-chaincode was being followed. Note that this example is for use with Hyperledger Fabric version 0.6.
The message is related to a PKCS11 package that is referenced by the example. This PKCS package requires a gcc compiler in order to build. I would suggest obtaining a gcc compiler and then trying to build the example again.

Building packer causes permission denied error

I am trying to build packer and I am getting this error:
go install golang.org/x/tools/cmd/vet: open /usr/lib/go/pkg/tool/linux_amd64/vet: permission denied
Makefile:40: recipe for target 'test' failed
make: *** [test] Error 1
Is the installer trying to access my /usr folder? Should I run this under root? How can I fix this?
go vet is special, in that it's a tool that needs to go in GOROOT. In most installations GOROOT is also user writable, but if you installed via a package manager it won't be.
To work around this, you can do this as root to avoid changing any permissions in your GOPATH:
GOPATH=/tmp/tmpGOPATH go get golang.org/x/tools/cmd/vet
rm -rf /tmp/tmpGOPATH
Since vet is a tool provided by the official distribution, not having it installed may be considered a bug in gentoo's go package. The official go binary distribution included the following tools:
addr2line
api
asm
cgo
compile
cover
dist
doc
fix
link
nm
objdump
pack
pprof
tour
trace
vet
yacc

Failure installing Go dependency

I have installed Go on my server using the golang repo for CentOS 6.4. The paths are set correctly and I can run go version. When I try to download the package below I receive this error. Any help is appreciated
go get github.com/fiorix/freegeoip
# github.com/fiorix/freegeoip
cannot create <nil>/go.o: No such file or directory
googling that error I came across a thread that suggests that this is a bug with detecting a missing TMPDIR environment variable, for compiling the source during go get.
run export TMPDIR=/tmp and it should work.
See here:
https://groups.google.com/forum/#!topic/golang-dev/LnxmgwB0r3Q

Resources