C functions have to be available when the Go package is built.  
yes,  but  static lib is kind of definition.

//#cgo CFLAGS: -I <include_path>
//#cgo CXXFLAGS="${CFLAGS}"
//#cgo LDFLAGS: -L <lib_path> -l<lib>

will this above work ? if I want to build a go static lib?


> how about go call c wrapper function  ,  c wrapper function  call c 
function
> in lib?

Please reply to the mailing list, not just to me.

In general all the C functions have to be available when the Go
package is built.

在 2017年4月19日星期三 UTC+8上午5:58:38,Ian Lance Taylor写道:
>
> On Tue, Apr 18, 2017 at 1:37 AM, hui zhang <fastf...@gmail.com 
> <javascript:>> 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.

Reply via email to