-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cgo: can't find type of function in shared library #32374
Comments
The cgo tool needs to figure out the type of |
What I don't understand is that if I set env vars for CGO_LDFLAGS with the content of the #cgo directive I have in the lib.go file it works. In the documentation it is said that "go build" shall use that directive in any of the go files of the project and use it during build. It seems not be the case. |
You have a newline between
|
That's working ! |
Yes it is See https://golang.org/cmd/cgo/
|
Thanks ! I didn't see this word. |
@AlexRouSg Thanks for spotting that. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64" GOBIN="" GOCACHE="/root/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/tmp/test" GOPROXY="" GORACE="" GOROOT="/opt/go" GOTMPDIR="" GOTOOLDIR="/opt/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" 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-build134582758=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I am trying to create a golang program which will use an external C library. I want to be able to use the "go get" without having to manually run swig.
I have created the following structure:
In the libfoo folder I have a simple shared library. The files contain: foo.c:
foo.h
That I've compiled it with:
Then the golang files: libfoo.swig
lib.go
And finally example_test.go
When I try to build with "go build -x" It seems that the cgo directives located in the "lib.go" file are not taken into account as I do not see the flags appearing in the output. Here is the output
What did you see instead?
f I set the CGO_LDFLAGS using an environment variable, it works. However I want to be able to just use "go get" without having those variables before.
I don't understand why go does not take my #cgo directive into account. Did I miss something ?
The text was updated successfully, but these errors were encountered: