-
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: unclear how to use //export and separate definition and declaration C code file #20970
Comments
Try
|
this changes the error to :
|
How do you build the package? Is pa.c placed in the same directory as pa.h and the Go code? |
yes all files are in the same directory , I just run |
Run |
without
|
Did you still have |
|
@cherrymui did you mean:
the info I found suggests that I need to set the exported go function as extern right ?
|
@krasi-georgiev
This looks like only a warning, i.e. build succeeded. You should see the executable. BTW, to suppress the warning, you need to declare |
yes that worked here are the final files
could you maybe explain what happens? |
By "declaration" in C, it means you need
No.
If pa.h is just a single line, you can write it directly in Go code, i.e. in Go code replace |
Now the problem is solved. |
I think maybe adding a small example in the docs would help others. |
I don't think we want an example of this in https://golang.org/cmd/cgo. It's too esoteric and is really more about C than about Go. This is more like a detail for a blog post somewhere. I'm going to close this issue. |
This part of the cgo doc is a bit unclear
I already have the declaration and the definition file in separate files, but I am still getting the duplicate symbols error.
What version of Go are you using (
go version
)?go version go1.8 darwin/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/krasimir"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
go run pa.h
What did you expect to see?
successful run
What did you see instead?
The text was updated successfully, but these errors were encountered: