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 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭