Closed
Description
I would like to use "zig cc" for easily cross compiling cgo dependent go code, however the "drop-in" c compiler replacement doesn't work.
Example cgo code
main.go
package main
//int Add(int a, int b){
// return a+b;
//}
import "C"
import "fmt"
func main() {
a := C.int(10)
b := C.int(20)
c := C.Add(a, b)
fmt.Println(c) // 30
}
other compilers
go build main.go //build works fine (uses gcc)
CC="clang" go build main.go //build works fine (uses clang)
zig cc
$ CC="zig cc" go build main.go
# runtime/cgo
info: Usage: zig [command] [options]
Commands:
build Build project from build.zig
build-exe Create executable from source or object files
build-lib Create library from source or object files
build-obj Create object from source or assembly
cc Use Zig as a drop-in C compiler
c++ Use Zig as a drop-in C++ compiler
env Print lib path, std path, compiler id and version
fmt Parse file and render in canonical zig format
init-exe Initialize a `zig build` application in the cwd
init-lib Initialize a `zig build` library in the cwd
libc Display native libc paths file or validate one
run Create executable and run immediately
translate-c Convert C code to Zig code
targets List available compilation targets
test Create and run a test build
version Print version number and exit
zen Print zen of zig and exit
General Options:
--help Print command-specific usage
error: unknown command: -E
go version go1.15.5 linux/amd64