How to get from cgo to exe

From the 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 from compiling here to exe?

+3
source share
2 answers

Try using go make files. Create a makefile like

# Makefile
CGOFILES=test.go
TARG=test

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

Running make will create a file _obj/test.athat you will need to associate with 6lor similar.

+6
source

Update for go1:

$ cat foo.go
package main

// #include <stdio.h>
// static void test() { printf("Hello, world\n"); }
import "C"

func main() {
    C.test()
}
$ go build foo.go
$  ./foo
Hello, world
+2
source

Source: https://habr.com/ru/post/1744432/


All Articles