On Wed, Apr 24, 2019 at 1:51 PM Nitish Saboo <nitish.sabo...@gmail.com>
wrote:
>
> Hi,
>
> I followed the link '
https://github.com/golang/go/wiki/cgo#function-variables' and  made the
following changes:
> 1)main.go
> package main
> //#cgo CFLAGS: -I./syslog-ng-3.6.2/
> //#cgo LDFLAGS: syslog-node.so
> //#cgo LDFLAGS: -L/usr/local/lib/ -lsyslog-ng
> //#cgo LDFLAGS: -L/usr/local/lib/syslog-ng -ldbparser
> //#cgo CFLAGS: -I.
> //void callOnMeGo_cgo(char *key, char *value, size_t value_len);  <<<<<

size_t is going to be undefined here.. Also the chars after ';' should
not be there

>>Why size_t, char is going to be undefined here ? I followed the exact
steps mentioned in 'https://github.com/golang/go/wiki/cgo#function-variables'
under the topic 'Function pointer callback'.
I have to pass the callback function to the C code.

> // #include "syslog-node1.h"
> //#include <stdlib.h>
> import "C"
>
> //export CallBack
> func CallBack(key *C.char, value *C.char, value_len C.size_t){
>
>     if remap, ok := field_mappings[C.GoString(key)]; ok {
>         fmt.Println(key, remap)//Need to check how field mappings work
>     }
>
> }
>
> func ReloadPatternDB(opts Y){

Where from type Y comes?
>> Y is simply a struct
type Y struct{
 x string
z map[string]string
}

>
>     x := C.CString(opts.x)
>     C.reload_pattern_db(x, (C.key_value_cb)(unsafe.Pointe
r(C.callOnMeGo_cgo)));
>
> }
>
> 2)Created a file 'cfuncs.go'
> ====================
> package main

Package main must have func main(). Where it is?

>>I had missed it.Added the func main()  but that did not resolve the issue.

*Following is the error that I am receiving:*

# command-line-arguments
*/tmp/go-build729657300/b001/_cgo_main.o:/tmp/go-build/cgo-generated-wrappers:2:
undefined reference to `callOnMeGo_cgo'*
collect2: error: ld returned 1 exit status
makefile:6: recipe for target 'main' failed
make: *** [main] Error 2


I feel the issue is with the makefile.Looks like the makefile is not able
to locate the method ' *callOnMeGo_cgo'.*Let me know if my understanding is
correct ?
Can someone help me in resolving the issue ?

Thanks

On Wed, Apr 24, 2019 at 5:39 PM Jan Mercl <0xj...@gmail.com> wrote:

> On Wed, Apr 24, 2019 at 1:51 PM Nitish Saboo <nitish.sabo...@gmail.com>
> wrote:
> >
> > Hi,
> >
> > I followed the link '
> https://github.com/golang/go/wiki/cgo#function-variables' and  made the
> following changes:
> > 1)main.go
> > package main
> > //#cgo CFLAGS: -I./syslog-ng-3.6.2/
> > //#cgo LDFLAGS: syslog-node.so
> > //#cgo LDFLAGS: -L/usr/local/lib/ -lsyslog-ng
> > //#cgo LDFLAGS: -L/usr/local/lib/syslog-ng -ldbparser
> > //#cgo CFLAGS: -I.
> > //void callOnMeGo_cgo(char *key, char *value, size_t value_len);  <<<<<
>
> size_t is going to be undefined here.. Also the chars after ';' should
> not be there
>
> > // #include "syslog-node1.h"
> > //#include <stdlib.h>
> > import "C"
> >
> > //export CallBack
> > func CallBack(key *C.char, value *C.char, value_len C.size_t){
> >
> >     if remap, ok := field_mappings[C.GoString(key)]; ok {
> >         fmt.Println(key, remap)//Need to check how field mappings work
> >     }
> >
> > }
> >
> > func ReloadPatternDB(opts Y){
>
> Where from type Y comes?
>
> >
> >     x := C.CString(opts.x)
> >     C.reload_pattern_db(x,
> (C.key_value_cb)(unsafe.Pointer(C.callOnMeGo_cgo)));
> >
> > }
> >
> > 2)Created a file 'cfuncs.go'
> > ====================
> > package main
>
> Package main must have func main(). Where it is?
>

-- 
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