-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
What version of Go are you using (go version
)?
$ go version go version go1.14.6 linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go envGO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vscode/.cache/go-build"
GOENV="/home/vscode/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/goapp/app/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build968699808=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I'm here from #35721 since it seems this particular case is not the same issue. Trying to import a static library using "import C" gives a "could not import C (no package for import C)" in vscode, the code however, can compile and run with no problems with go build.
sample go code:
package main
// #cgo CFLAGS: -g -Wall -I/usr/src/myapp
// #cgo LDFLAGS: /usr/src/myapp/libdoecho.a
// #include "libdoecho.h"
import "C"
import "unsafe"
import "fmt"
func test1() {
aCstring := C.CString("Hello")
res := C.doecho(aCstring)
aGOstring := C.GoString(res)
C.free(unsafe.Pointer(aCstring))
C.freeThePointer(res)
fmt.Println("%v", aGOstring)
}
sample .h code:
#ifndef libdoecho
#define libdoecho
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
char *doecho(const char *s);
void freeThePointer(char *s);
#endif /* libdoecho */
libdoecho.a is a library wich exposes the "doecho" and "freeThePointer" functions. A string enters and a string is returned.
What did you expect to see?
import C should not give the "could not import C (no package for import C)" error on vscode, since the code does compile and run without problems with go build.
What did you see instead?
A "could not import C (no package for import C)" error.