LoginSignup
8
5

More than 5 years have passed since last update.

Visual Studio CodeでGoのデバッグ環境作ろうとしたら失敗した件

Posted at

はじめに

とかを参考に、

  • Windows 7 64bit
  • Go (version go1.7.1 windows/amd64)
  • Visual Studio Code (version 1.5.2)

という環境で、Goのデバッグ環境を作ろうしたら失敗した。
これはその解決までのメモ

起こったエラー

一通りインストール・設定を終えて、GoコードをVisual Studio Codeでデバッグしようとすると、
can't load package: package internal: no buildable Go source files in %GOROOT%\src\internal
とエラーとなった。

goerr.png

ここでコマンドラインで以下を確認

go build .\main.go

→成功

dlv debug .\main.go

→失敗(以下のようにVisual Studio Codeと似たようなエラーが出た)

can't load package: package internal: no buildable Go source files in D:\go\src\internal
can't load package: package ****/main.go: cannot find package "****/main.go" in any of:
        ****\main.go (from $GOROOT)
        ****\main.go (from $GOPATH)
exit status 1

解決策

stackoverflowで同じ悩みを持つ人がいた。

この人のとおり、ちょっと昔のコードを自前でビルドすることにした。

※なお、delveのプロジェクトで割りと最近(2016/9/20時点)で以下の似たようなIssueが出ているのでもう少ししたら解決するのかも?
https://github.com/derekparker/delve/issues/634

1. cygwin・mingw環境の準備

私は、mobaXtermを使っていたのですでに導入済みだった。
※使いやすいよ!

ただし、makeとかgccとか入ってなかったのでインストール

apt-get install gcc-core
apt-get install make

2. delveレポジトリへの移動と、昔のコードのcheckout

go getして取得していたdelveのレポジトリに移動します。

cd $GOPATH/src/github.com/derekparker/delve

そして、過去のコミットにチェックアウトします。
私の場合は、51c39ed17132372144eaedc29b0248c5f30f71a1にチェックアウトしました。

git checkout 51c39ed17132372144eaedc29b0248c5f30f71a1

3. delveのビルド・インストール

正常に動いていた(と思われる)版をビルド、インストールします。
これで、dlv.exeが入れ替わります。

make build
make install
go build -ldflags="-X main.Build=51c39ed17132372144eaedc29b0248c5f30f71a1" github.com/derekparker/delve/cmd/dlv
go install -ldflags="-X main.Build=51c39ed17132372144eaedc29b0248c5f30f71a1" github.com/derekparker/delve/cmd/dlv

解決

やったね!:ok_hand:
gook.png

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5