tags:

views:

163

answers:

1

From a basic test program. . .

package main

/*
#include <stdio.h>
static void test() {
        printf("hello world");
}
*/
import "C"

func main() {
        C.test();
}

I do "cgo hello_cgo.go" and get:

_cgo_.o
_cgo_defun.c
_cgo_gotypes.go 
hello_cgo.cgo1.go 
hello_cgo.cgo2.c

How do I go about compiling from here to an exe?

+4  A: 

Try using the go makefiles. Create a makefile like

# Makefile
CGOFILES=test.go
TARG=test

include $(GOROOT)/src/Make.$(GOARCH)
include $(GOROOT)/src/Make.pkg

Running make will then produce the file _obj/test.a, which you'll have to link with 6l or similar.

Scott Wales
Thanks! That worked. Appreciate the quick response.
Kawili-wili