github.com/giovannyortegon/go@v0.0.0-20220115155912-8890063f5bdd/src/BlackHatGo/Chap01/MoreCallC/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  import "C"
     9  import (
    10  	"fmt"
    11  	"unsafe"
    12  )
    13  
    14  func main() {
    15  	fmt.Println("Going to call a C function")
    16  	C.cHello()
    17  	fmt.Println("Going to call aother 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 prefectly done!")
    23  }