I am trying to compile a simple go program using gccgo. My code uses cgo thou, gccgo couldn't compile it. This is my code (which compiles using go compiler):
package main
// #include <stdio.h>
// #include <stdlib.h>
//
// static void myprint(char* s) {
// printf("%s\n", s);
// }
import "C"
import "fmt"
func main(){
fmt.Println("Start")
cs := C.CString("Print from C")
C.myprint(cs)
fmt.Println("End")
}
when I compile the code using gccgo main.go -o gccoutput
I get:
main.go:9:9: error: import file ‘C’ not found
import "C"
^
main.go:13:8: error: reference to undefined name ‘C’
cs := C.CString("Print from C")
^
main.go:14:2: error: reference to undefined name ‘C’
C.myprint(cs)
^
any ideas how to solve this?
EDIT: I am trying to compile to ppc using the gccgo, and I don't want to use cross-compilation process of go compiler. I have tried to do (as suggested in the comments):
go build -compiler=gccgo
and it worked. Thou, when I do:
go build -comiler=powerpc-linux-gnu-gccgo main.go
I get:
invalid value "powerpc-linux-gnu-gccgo" for flag -compiler: unknown compiler "powerpc-linux-gnu-gccgo"
usage: go build [-o output] [-i] [build flags] [packages]
Run 'go help build' for details.