如何在不使用make的情况下使用cgo?

I use a custom build tool to compile go projects and I need a way to use cgo in my project.

The problem is that the cgo documentation only tells you how to use it with make.

What I really need to know is which generated files to process with which tools and in what order it needs to be done. I tried to read make.pkg in the go source dir but my best effort fails.

My test dll is very simple, a single function that returns 1 every time it is called and the go code to use this function is similarly simple.

The output from the console produced by a successful run of make on a cgo project would be very helpful.

Output of running make on 32-bit Linux in directory misc/cgo/life:

# gomake _obj/life.a
CGOPKGPATH= cgo --  life.go 
touch _obj/_cgo_run
8g  -o _go_.8  _obj/life.cgo1.go _obj/_cgo_gotypes.go
8c -FVw -I ${GOROOT}/pkg/linux_386 -I . -o "_cgo_defun.8" _obj/_cgo_defun.c
gcc -m32 -I . -g -fPIC -O2 -o _cgo_main.o -c   _obj/_cgo_main.c
gcc -m32 -g -fPIC -O2 -o c-life.o -c   c-life.c
gcc -m32 -I . -g -fPIC -O2 -o life.cgo2.o -c   _obj/life.cgo2.c
gcc -m32 -I . -g -fPIC -O2 -o _cgo_export.o -c   _obj/_cgo_export.c
gcc -m32 -g -fPIC -O2 -o _cgo1_.o _cgo_main.o c-life.o life.cgo2.o _cgo_export.o  
cgo -dynimport _cgo1_.o >_obj/_cgo_import.c_ && mv -f _obj/_cgo_import.c_ _obj/_cgo_import.c
8c -FVw -I . -o "_cgo_import.8" _obj/_cgo_import.c
rm -f _obj/life.a
gopack grc _obj/life.a _go_.8  _cgo_defun.8 _cgo_import.8 c-life.o  life.cgo2.o _cgo_export.o

The line cgo -- life.go creates the following files:

_obj/_cgo_.o
_obj/life.cgo1.go
_obj/life.cgo2.c
_obj/_cgo_gotypes.go
_obj/_cgo_defun.c
_obj/_cgo_main.c
_obj/_cgo_flags
_obj/_cgo_export.c
_cgo_export.h

"I use a custom build tool to compile go projects and I need a way to use cgo in my project."

... and this approach leads to problems. Using the standard way with a Makefile is simple, easy, proven, documented, etc.

I realize I'm not (directly) answering your question. Instead my "answer" is: I strongly suggest to use the standard way. Don't create problems for your self by choosing other, not directly supported options.

That said, I think there is a way to avoid the Makefiles, I just never been there, sorry. I'm usually lazy/short of time, so I use the simplest/fastest way to get things done. You might want to try the same ;-)