duannuci4008 2018-11-13 03:51
浏览 131
已采纳

VsCode Go扩展程序调试Example_c.c文件而不是实际文件

I just tried to execute a Hello World from VSCode 1.28.2 (Windows 8.1) in a C:\Scripts\hello_world.go file:

package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello, Gopher!")
}

My environment is as follows:

  • I installed Go from scratch using the Windows installer:
$ go version
go version go1.11.2 windows/amd64

go get -u github.com/derekparker/delve/cmd/dlv

  • Checked with SystemPropertiesAdvanced:
    • Local Variable GOPATH = %USERPROFILE%\go
    • Local Variable PATH adds %USERPROFILE%\go\bin
    • System Variable PATH adds C:\Go\bin
    • System Variable GOROOT = C:\Go\
  • I have MinGW64, GitBash and MinGW 1.0 (However I don't see how that could affect running Go from VSCode)
  • Running from cmd.exe runs the program without problems at all:
C:\Scripts>go run hello_world.go
Hello, Gopher!

In VSCode settings my global go.gopath and go.goroot settings are:

  // 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

So I customized the variables from VSCode as follows:

{
    "editor.renderControlCharacters": false,
    "go.inferGopath": true,
    "go.goroot": "C:\\go",
}

Now this is the weird part. When I hit Ctrl+F5 compilation takes a "Example_c.c" file (?) and reports errors with that file (which I never created or even knew that existed):

# _/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

I already tried deleting all my temporary files and restarted VsCode multiple times. The whole experience to setup a Go environment to debug a hello world is really dissapointing.

What else can I check? Any hints?

  • 写回答

1条回答 默认 最新

  • douhang5493 2018-11-13 05:34
    关注

    Your GOPATH should point to "C:\Scripts". Then point the "program" variable in launch.json to "C:\Scripts" to run it in Debug Mode.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号