VsCode Go 扩展调试 Example_c.c 文件而不是实际文件
VsCode Go extension debugs Example_c.c file instead of actual file
我刚刚尝试在 C:\Scripts\hello_world.go 文件中从 VSCode 1.28.2 (Windows 8.1) 执行 Hello World:
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, Gopher!")
}
我的环境如下:
- 我使用 Windows 安装程序从头开始安装 Go:
$ go version
go version go1.11.2 windows/amd64
- 安装在 C:\Go
- 已安装 VSCode 转扩展:https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go
- 已安装调试器:
go get -u github.com/derekparker/delve/cmd/dlv
- 使用 SystemPropertiesAdvanced 检查:
- 局部变量 GOPATH = %USERPROFILE%\go
- 本地变量 PATH 添加 %USERPROFILE%\go\bin
- 系统变量PATH添加C:\Go\bin
- 系统变量 GOROOT = C:\Go\
- 我有 MinGW64、GitBash 和 MinGW 1.0(但是我看不出这会如何影响 运行 从 VSCode 开始)
- 运行 from cmd.exe 运行程序完全没有问题:
C:\Scripts>go run hello_world.go
Hello, Gopher!
在 VSCode 设置中,我的全局 go.gopath 和 go.goroot 设置是:
// Specify GOPATH here to override the one that is set as environment variable. The inferred GOPATH from workspace root overrides this, if go.inferGopath is set to true.
"go.gopath": null
// Specifies the GOROOT to use when no environment variable is set.
"go.goroot": null
所以我自定义了VSCode的变量如下:
{
"editor.renderControlCharacters": false,
"go.inferGopath": true,
"go.goroot": "C:\go",
}
现在这是奇怪的部分。当我按下 Ctrl+F5 时,编译会获取一个 "Example_c.c" 文件 (?) 并报告该文件的错误(我从未创建过甚至不知道它存在):
# _/c_/Scripts
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_x003.o: In function `main':
./Example_c.c:1: multiple definition of `main'
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_cgo_main.o:/tmp/go-build/_cgo_main.c:1: first defined here
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_x004.o: In function `main':
./Test_C-01.c:3: multiple definition of `main'
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_cgo_main.o:/tmp/go-build/_cgo_main.c:1: first defined here
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_x005.o: In function `main':
./Test_C-02.c:3: multiple definition of `main'
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_cgo_main.o:/tmp/go-build/_cgo_main.c:1: first defined here
collect2: ld returned 1 exit status
# _/c_/Scripts
Example_c.c: In function 'main':
Example_c.c:2:3: warning: incompatible implicit declaration of built-in function 'printf'
Example_c.c:4:19: warning: incompatible implicit declaration of built-in function 'malloc'
Example_c.c:9:3: warning: incompatible implicit declaration of built-in function 'free'
exit status 2
Process exiting with code: 1
我已经尝试删除所有临时文件并重新启动 VsCode 多次。设置 Go 环境来调试 hello world 的整个体验真的很令人失望。
我还能检查什么?有什么提示吗?
您的 GOPATH 应指向 "C:\Scripts"。然后在调试模式下将launch.json中的"program"变量指向"C:\Scripts"到运行。
我刚刚尝试在 C:\Scripts\hello_world.go 文件中从 VSCode 1.28.2 (Windows 8.1) 执行 Hello World:
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, Gopher!")
}
我的环境如下:
- 我使用 Windows 安装程序从头开始安装 Go:
$ go version go version go1.11.2 windows/amd64
- 安装在 C:\Go
- 已安装 VSCode 转扩展:https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go
- 已安装调试器:
go get -u github.com/derekparker/delve/cmd/dlv
- 使用 SystemPropertiesAdvanced 检查:
- 局部变量 GOPATH = %USERPROFILE%\go
- 本地变量 PATH 添加 %USERPROFILE%\go\bin
- 系统变量PATH添加C:\Go\bin
- 系统变量 GOROOT = C:\Go\
- 我有 MinGW64、GitBash 和 MinGW 1.0(但是我看不出这会如何影响 运行 从 VSCode 开始)
- 运行 from cmd.exe 运行程序完全没有问题:
C:\Scripts>go run hello_world.go Hello, Gopher!
在 VSCode 设置中,我的全局 go.gopath 和 go.goroot 设置是:
// Specify GOPATH here to override the one that is set as environment variable. The inferred GOPATH from workspace root overrides this, if go.inferGopath is set to true.
"go.gopath": null
// Specifies the GOROOT to use when no environment variable is set.
"go.goroot": null
所以我自定义了VSCode的变量如下:
{
"editor.renderControlCharacters": false,
"go.inferGopath": true,
"go.goroot": "C:\go",
}
现在这是奇怪的部分。当我按下 Ctrl+F5 时,编译会获取一个 "Example_c.c" 文件 (?) 并报告该文件的错误(我从未创建过甚至不知道它存在):
# _/c_/Scripts
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_x003.o: In function `main':
./Example_c.c:1: multiple definition of `main'
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_cgo_main.o:/tmp/go-build/_cgo_main.c:1: first defined here
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_x004.o: In function `main':
./Test_C-01.c:3: multiple definition of `main'
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_cgo_main.o:/tmp/go-build/_cgo_main.c:1: first defined here
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_x005.o: In function `main':
./Test_C-02.c:3: multiple definition of `main'
C:\Users\Mike\AppData\Local\Temp\go-build530760830\b001\_cgo_main.o:/tmp/go-build/_cgo_main.c:1: first defined here
collect2: ld returned 1 exit status
# _/c_/Scripts
Example_c.c: In function 'main':
Example_c.c:2:3: warning: incompatible implicit declaration of built-in function 'printf'
Example_c.c:4:19: warning: incompatible implicit declaration of built-in function 'malloc'
Example_c.c:9:3: warning: incompatible implicit declaration of built-in function 'free'
exit status 2
Process exiting with code: 1
我已经尝试删除所有临时文件并重新启动 VsCode 多次。设置 Go 环境来调试 hello world 的整个体验真的很令人失望。
我还能检查什么?有什么提示吗?
您的 GOPATH 应指向 "C:\Scripts"。然后在调试模式下将launch.json中的"program"变量指向"C:\Scripts"到运行。