7

Please see the following screenshot:

vscode with golang import "C" error

It says:

could not import C (no package data for import path C)

I have attached an example project that reproduces the failure, here: https://github.com/microsoft/vscode/files/3783446/example-project.zip

I am using Go 1.13 with the latest versions of each extension for Go and C/C++. There is no compiler error, and this is specifically seemingly isolated as a "vscode problem".

Is there a way to fix this vscode problem?

Ace
  • 463
  • 3
  • 6
  • 16

3 Answers3

5

This is a bug in gopls tool distributed in the official golang packages.

Here are the issue links:


info from issue report:

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.

Ace
  • 463
  • 3
  • 6
  • 16
1

That's a bug with VSCode and I've written a medium article for this issue.

https://medium.com/@mourya.g9/setting-up-confluent-kafka-client-for-golang-with-vscode-7a27bb94220b. Hope this helps.

mourya venkat
  • 267
  • 3
  • 10
0

The problem is the extra new line between the import, you can try with the following:

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

CGO import example Have a look here for other example related to CGO:
https://github.com/alessiosavi/GoUtils/blob/master/GoUtils.go

alessiosavi
  • 2,753
  • 2
  • 19
  • 38