doubi1797 2019-04-12 02:39
浏览 27
已采纳

dlv调试失败,因为同一包中的对象未定义

I filed a bug for this over at the delve site. So, to explain what's going on. I have 2 files in the same package, main.go and common.go. In main.go, it uses some structure from common.go and when i run

dlv debug --listen=:2345 --headless --api-version=2 --log main.go

it fails with 'undefined: NewSimpleStruct' and i am not sure what i am doing wrong.

Here's what the Go files contain,

//main.go
package main

import (
    "fmt"
)

func main() {
    fmt.Println("HELLO WORLD!")
    segasaturn := NewSimpleStruct("SS", 69)
    segasaturn.WhoAmI()

    fmt.Println("BYE WORLD!")
}


//common.go
package main

import "fmt"

type simpleStruct struct {
    name string
    id   int
}

func NewSimpleStruct(name string, id int) *simpleStruct {
    return &simpleStruct{name, id}
}

func (ss *simpleStruct) WhoAmI() {
    fmt.Printf("name: %s, id: %d
", ss.name, ss.id)
}
  • 写回答

2条回答 默认 最新

  • dougong2005 2019-04-12 10:08
    关注

    A common error, and it's not delve's fault; note that you also can't go build main.go here.

    You need to do go build . or go build main.go common.go.

    Similarly just put all the files or a dot(.) instead of main.go to include all the .go files in the directory

    dlv debug --listen=:2345 --headless --api-version=2 --log .

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端