【问题标题】:VSCode import "C" fails on modulesVSCode 导入“C”在模块上失败
【发布时间】:2020-02-18 15:58:45
【问题描述】:

请看以下截图:

上面写着:

无法导入 C(导入路径 C 没有包数据)

我附上了一个重现失败的示例项目,这里:https://github.com/microsoft/vscode/files/3783446/example-project.zip

我正在使用 Go 1.13 以及 Go 和 C/C++ 的每个扩展的最新版本。 没有编译器错误,而且这似乎是一个“vscode 问题”。

有没有办法解决这个 vscode 问题?

【问题讨论】:

  • 这是编译错误还是只是 IDE 不知道 CGo?
  • @gonutz 没有编译错误,我会用那个细节来澄清这个问题。

标签: c go visual-studio-code cgo


【解决方案1】:

这是 golang 官方包中分发的 gopls 工具中的一个错误。

这里是问题链接:


问题报告中的信息:

internal/lsp: use Go/cgo source files instead of generated files

Using CompiledGoFiles was causing metadata lookups to fail for cgo
packages because it includes generated files in the Go build cache
when the built-in 'go list' driver is used.  GoFiles includes both
Go and cgo original file names, allowing metadata lookups to
succeed.

【讨论】:

    【解决方案2】:

    这是 VSCode 的一个错误,我为此问题写了一篇中等文章。

    https://medium.com/@mourya.g9/setting-up-confluent-kafka-client-for-golang-with-vscode-7a27bb94220b。希望这会有所帮助。

    【讨论】:

    • 我已经在 vscode github 仓库提交了一个问题
    【解决方案3】:

    问题是导入之间有多余的新行,您可以尝试以下操作:

    // #cgo CFLAGS: -g -Wall
    // #include <stdio.h>
    // #include <stdlib.h>
    // #include <string.h>
    // #include "cutils.h"
    import "C"
    import (
        "bufio"
        "encoding/json"
    // ...
    )
    

    在这里查看与 CGO 相关的其他示例:
    https://github.com/alessiosavi/GoUtils/blob/master/GoUtils.go

    【讨论】:

      猜你喜欢
      • 2016-11-12
      • 2019-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      相关资源
      最近更新 更多