github.com/giovannyortegon/go@v0.0.0-20220115155912-8890063f5bdd/src/MasterGO/Chap02-GoInternals/callC.go (about) 1 package main 2 3 /* 4 #cgo CFLAGS: -I${SRCDIR}/callClib 5 #cgo LDFLAGS: ${SRCDIR}/callC.a 6 #include<stdlib.h> 7 #include<callC.h> 8 */ 9 import "C" 10 import ( 11 "fmt" 12 "unsafe" 13 ) 14 func main() { 15 fmt.Println("Going to call another C function!") 16 C.cHello() 17 fmt.Println("Going to call another C function!") 18 myMessage := C.CString("This is Mihalis!") 19 defer C.free(unsafe.Pointer(myMessage)) 20 C.printMessage(myMessage) 21 22 fmt.Println("All perfectly done!") 23 }