-
-
Save jordanorelli/4091d8366f0651aad0fb8dff6ce82e21 to your computer and use it in GitHub Desktop.
minimum viable cgo with a header file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int from_c() { | |
return 12; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
/* | |
#include "z.h" | |
*/ | |
import "C" | |
func main() { | |
fmt.Printf("Hello. Value from C: %v\n", C.from_c()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int from_c(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
put in a directory and build with
go build
.go build z.go
or any variation ofgo run
will not work, since specifying a filename tells the Go toolchain to only use those Go files and not other files, which thwarts cgo.