On Tue, Apr 18, 2017 at 1:37 AM, hui zhang <fastfad...@gmail.com> wrote: > add a c wrapper around cfunc.h not help either. > > 在 2017年4月18日星期二 UTC+8下午4:36:26,hui zhang写道: >> >> I want to embedded go code in c/c++ program. >> my approach as below, however go code can not be compiled >> C main() --> go func --> c func(in static lib) >> >> >> <main.c> >> #include "libgofunc.h" >> int main() { >> Gofunc(); >> } >> >> <gofunc.go> CGO_ENABLED=1 go build -buildmode=c-archive -o >> libgofunc.a --> error >> >> Undefined symbols for architecture x86_64: "_cfunc" >> >> package main >> >> //#inclue "cfunc.h" >> import "C" >> //export Gofunc >> func Gofunc() { >> C.cfunc() //cfunc is in a static lib >> }func main() {} // Required but ignored >> >> <cfunc.h , cfunc.a> >> extern void cfunc();
We don't currently support a Go package calling a C function that is not yet defined. You have to actually provide a definition for the function, not just a declaration. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.