Calling go functions from C


i am trying to write a code, where i call Go API to return a value.
i am making use of portstatus.c example in the examples/dp/find_next directory.

i have written a gofile.
did -> go build -buildmode=c-shared -o myfunc.a myfunc.go

the above command generated .a file(library) and myfunc.h file

i included this .h header file in portstatus.c code
and tried calling the func get_entry defined in myfunc.go

when i did make all
i got this error
root@mars01> make all
cc -o portstatus portstatus.o /opt/confd//lib/libconfd.a -lpthread -lm
portstatus.o: In function get_elem': /opt/confd/examples.confd/dp/find_next/portstatus.c:181: undefined reference toget_entry’
collect2: error: ld returned 1 exit status

i was supposed to link the static library using
gcc -o portstatus portstatuc.c myfunc.a

this gave me a error
root@mars01> gcc -o portstatus portstatus.c gofunc.a
portstatus.c:14:23: fatal error: confd_lib.h: No such file or directory
#include <confd_lib.h>
compilation terminated.

Can someone let me know the steps in how to make use of GO functions in C and how to compile it

Thanks in Advance

Hi Roopa,

In your second attempt to link the portstatus app you forgot the rest of the libraries portstatus needs. The command, assuming that you already have portstatus.o, should be:
$ cc -o portstatus portstatus.o /opt/confd//lib/libconfd.a -lpthread -lm myfunc.a


You need to look somewhere else for help in calling Go from C. That has nothing to do with ConfD. We can help you with calling our supported APIs; C, etc. and using C with ConfD. Calling Go from your C application is out-of-scope and does not involve anything from ConfD.

Anyway we resolved it by ourselves