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):
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)
^
$ go version
go version devel +758ac371ab Tue Aug 25 21:15:43 2020 +0000 linux/amd64
$ go run tom.go
Start
Print from C
End
gccgo:
$ gccgo --version
gccgo (Ubuntu 10-20200411-0ubuntu1) 10.0.1 20200411 (experimental) [master revision bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566]
$ go run -compiler=gccgo tom.go
Start
Print from C
End
$
Can you explain what the -compiler mean?
I have tried to do: go build -compiler=powerpc-linux-gnu-gccgo main.go
and got:
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.