7

I am trying to build the package github.com/go-delve/delve/cmd/dlv@2f13672765fe and have the resulting executable named dlv-dap.

Under older versions of go (pre 1.16) I was able to accomplish this by running the following commands.

  • go get github.com/go-delve/delve/cmd/dlv@2f13672765fe
  • go build -o dlv-dap github.com/go-delve/delve/cmd/dlv@2f13672765fe

Under v1.17 this no longer works, instead the command go get github.com/go-delve/delve/cmd/dlv@2f13672765fe throws the following error

go: go.mod file not found in current directory or any parent directory. 'go get' is no longer supported outside a module. To build and install a command, use 'go install' with a version, like 'go install example.com/cmd@latest' For more information, see https://golang.org/doc/go-get-install-deprecation or run 'go help get' or 'go help install'.

Reading the information link provided in the error it seems there is no longer a way to download/build a golang package with a customized name (e.g. -o my_custom_named_executable).

Is my understanding correct or is there another way to accomplish this?

6
  • Actually you just have to do go install instead of go get, with the same syntax. Now you can only run go get in a go module directory to add a dependency. Commented Jan 22, 2022 at 20:36
  • go install does not accept the -o flag... as stated I want a custom named executable, go install does not offer this level of control Commented Jan 22, 2022 at 20:40
  • Is manually renaming the executable after installing an option? Commented Jan 22, 2022 at 20:41
  • Yes indeed, you are confusing install and build. You don't even need the build command, go install will add the binary to your $GOPATH/bin directory without you needing to build it yourself. Commented Jan 22, 2022 at 20:43
  • go build still exists to compile from sources, what you can do if you want to build it yourself is clone the project and run your go build command from the root. Commented Jan 22, 2022 at 20:44

2 Answers 2

6

Here are 2 solutions to do what you want:

First solution: go install

This will install the dlv executable to your $GOPATH/bin directory.

go install github.com/go-delve/delve/cmd/dlv@2f13672765fe 

Second solution: install from source:

git clone [email protected]:go-delve/delve.git cd delve git checkout 2f13672765fe go build -o dlv ./cmd/dlv 

This will build dlv executable to the root of the project.

Run Delve DAP

Use dlv dap subcommand, dlv-dap is just an alias to that.

Sign up to request clarification or add additional context in comments.

4 Comments

First Solution: results in an executable named dlv not dlv-dap
Second Solution: this seems to work
Indeed, this is the official name of the executable. dlv-dap is now a subcommand of dlv, just run dlv dap instead.
If you are on Linux or Macos you can add an alias for dlv-dap to run dlv dap with alias command added to your shell configuration (e.g, .bashrc)
0

The name given to the binary is defined in the mod-file. In this case the mod-file contains:

module github.com/go-delve/delve 

If you clone the repository using git you can change this to:

module github.com/go-delve/dev-dap 

If you now start

go build
the new name will be assigned.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.