在 Visual Studio Code 中如何使用 Cgo 为 Go 代码调试
时间:2024-02-27
浏览:479
作者:佚名
“纵有疾风来,人生不言弃”,这句话送给正在学习Golang的朋友们,也希望在阅读本文《在 Visual Studio Code 中如何使用 Cgo 为 Go 代码调试》后,能够真的帮助到大家。我也会在后续的文章中,陆续更新Golang相关的技术文章,有好的建议欢迎大家在评论留言,非常感谢!
问题内容
如果没有 cgo 代码,我可以在 visual studio code 中设置断点并单步执行 go 代码,而不会出现问题。一旦go代码中调用了cgo代码,断点基本上会被忽略,尽管应用程序运行良好。
这是片段:
//hello.c
#include <stdio.h>
void Test() {
printf("C: Hello world");
}
//hello.go
package main
// #cgo LDFLAGS: -Wl,--allow-multiple-definition
// #cgo CFLAGS: -Wall -std=c99 -O1 -g
/*
#include "hello.c"
*/
import "C"
import "fmt"
func main() {
//Call to void function without params
C.Test()
fmt.Printf("Go: Hello world\n")
}
//launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "learning"
}
]
}正确答案
这是目前已知的 bug。这可能会在 go 1.18 中得到修复。在Linux上可以正常调试。
文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《在 Visual Studio Code 中如何使用 Cgo 为 Go 代码调试》文章吧,也可关注golang学习网公众号了解相关技术文章。
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
站内热门
最新文章
12.01
12.01
热门专题
