Mastering-Go-Second-Edition/ch02/callC.go
2019-01-10 09:18:16 +02:00

24 lines
444 B
Go

package main
// #cgo CFLAGS: -I${SRCDIR}/callClib
// #cgo LDFLAGS: ${SRCDIR}/callC.a
// #include <stdlib.h>
// #include <callC.h>
import "C"
import (
"fmt"
"unsafe"
)
func main() {
fmt.Println("Going to call a C function!")
C.cHello()
fmt.Println("Going to call another C function!")
myMessage := C.CString("This is Mihalis!")
defer C.free(unsafe.Pointer(myMessage))
C.printMessage(myMessage)
fmt.Println("All perfectly done!")
}