Skip to content
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

misc/cgo/testcdefs doesn't work: C source files not allowed when not using cgo #9528

Closed
keithkml opened this issue Jan 7, 2015 · 4 comments
Milestone

Comments

@keithkml
Copy link

keithkml commented Jan 7, 2015

I'm new to Go, and I'm attempting to learn about how to interoperate between C and Go. I thought a good way to learn would be to go through some of the examples in the repo. However it appears that a change in Go 1.4 has made one of the examples not work anymore. Others seem to be having related issues: #9132

https://github.com/golang/go/tree/master/misc/cgo/testcdefs

$ go version
go version go1.4 darwin/amd64
$ cd misc/cgo/testdefs
$ ./test.bash 
can't load package: package .: C source files not allowed when not using cgo: cdefstest.c main.c
@ianlancetaylor
Copy link
Contributor

You're right: testcdefs doesn't work any more, and we should fix that or delete the directory.

That said, that directory is not an example of how to interoperate between C and Go. It's a test of the -cdefs option of the cgo tool, which is not intended for use by anybody other than people bootstrapping a Go port to a new operating system.

@ianlancetaylor ianlancetaylor added this to the Go1.5 milestone Jan 7, 2015
@ianlancetaylor ianlancetaylor self-assigned this Jan 7, 2015
@keithkml
Copy link
Author

keithkml commented Jan 7, 2015

Hi @ianlancetaylor, remember me from the Berkeley google shuttle? :)

I guess I was mistaken about the purpose of that directory – the blog post at http://blog.golang.org/c-go-cgo links to misc/cgo with the phrase "The cgo examples in the Go tree demonstrate more advanced concepts."

@keithkml
Copy link
Author

keithkml commented Jan 7, 2015

I'm brand new to Go, and made the mistake of getting my feet wet by attempting to call into Go from an existing C++-based mobile app :) Probably should've started with something simpler.

The docs seem to thoroughly cover how to call into C from Go, but not the other way around...

@ianlancetaylor
Copy link
Contributor

Unfortunately at present you have to start with a Go program. There is as yet no support for calling a Go library from a C/C++ program.

It is possible to have a Go program that calls C code that calls Go code, though (http://golang.org/cmd/cgo/#hdr-C_references_to_Go).

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants