Hi Tamas,

I made it *C.Foo but still getting the error.

main.go
=======

type Callback struct {
Func     func(*C.char , *C.char , C.size_t, C.int)
UserData int32
}

Calling C code in the following manner
=========================================

C.initialize_engine(pattern_db, module_path,
(*C.Foo)(unsafe.Pointer(&Callback{
Func:     C.callOnMeGo_cgo
UserData: C.int(1),
})))

//export ParsedData
func ParsedData(key *C.char, value *C.char, value_len C.size_t, work C.int)
{
fmt.Println("WORK:")
fmt.Print()
//performing some operation here
}

cfunc.go
=========

package main

/*

#include <stdio.h>

// The gateway function
void callOnMeGo_cgo(char *key, char *value, size_t value_len, int work)
{
//printf("C.callOnMeGo_cgo(): called");
void ParsedData(const char *key, const char *value, size_t value_len, int
work);
ParsedData(key, value, value_len, work);
}
*/
import "C"



syslog-node.h
===============
#ifndef _TEST_H_
#define _TEST_H_

#include <stdlib.h>

typedef void (*key_value_cb)(const char* key, const char* value, size_t
value_len, int work);
typedef struct Foo{
    key_value_cb cbnitish;
    int data;
}Foo;
int initialize_engine(const char* filename, const char* module_path, Foo
*cb);
int reload_pattern_db(const char* filename, Foo *cb);

#endif

syslog-node.c
===============

gboolean pdbtool_accumulate_fields(NVHandle handle, const gchar *name,
const gchar *value, gssize length, gpointer user_data)
{
  user_data->cbnitish(name, value, length, user_data->data);// Callback
happening here
  return FALSE;
}

Eventually user_data will get the instance of the struct.

Looks like there is some issue with my  struct declaration in Go.Can some
please guide me  as in what is the issue ?


Error:
====
go build -v -x main.go cfuncs.go
WORK=/tmp/go-build037176041
command-line-arguments
mkdir -p $WORK/b001/
cd /home/nsaboo/Documents/goworkspace/src/poc
pkg-config --cflags -- syslog-ng eventlog
pkg-config --libs -- syslog-ng eventlog
CGO_LDFLAGS='"-g" "-O2" "syslog-node.so" "-L/usr/local/lib/" "-lsyslog-ng"
"-L/usr/local/lib/syslog-ng" "-ldbparser" "-L/usr/local/lib"
"-Wl,--export-dynamic" "-lgmodule-2.0" "-pthread" "-lgthread-2.0"
"-pthread" "-lglib-2.0" "-lsyslog-ng" "-lglib-2.0" "-levtlog"'
/usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b001/ -importpath
command-line-arguments -- -I/usr/local/include/syslog-ng
-I/usr/local/include/syslog-ng/ivykis -I/usr/local/include/eventlog
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I
$WORK/b001/ -g -O2 -I/usr/local/include/ ./main.go ./cfuncs.go
cd $WORK
gcc -fno-caret-diagnostics -c -x c - || true
gcc -Qunused-arguments -c -x c - || true
gcc -fdebug-prefix-map=a=b -c -x c - || true
gcc -gno-record-gcc-switches -c -x c - || true
cd $WORK/b001
TERM='dumb' gcc -I /home/nsaboo/Documents/goworkspace/src/poc -fPIC -m64
-pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build
-gno-record-gcc-switches -I/usr/local/include/syslog-ng
-I/usr/local/include/syslog-ng/ivykis -I/usr/local/include/eventlog
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I ./
-g -O2 -I/usr/local/include/ -o ./_x001.o -c _cgo_export.c
TERM='dumb' gcc -I /home/nsaboo/Documents/goworkspace/src/poc -fPIC -m64
-pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build
-gno-record-gcc-switches -I/usr/local/include/syslog-ng
-I/usr/local/include/syslog-ng/ivykis -I/usr/local/include/eventlog
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I ./
-g -O2 -I/usr/local/include/ -o ./_x002.o -c main.cgo2.c
TERM='dumb' gcc -I /home/nsaboo/Documents/goworkspace/src/poc -fPIC -m64
-pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build
-gno-record-gcc-switches -I/usr/local/include/syslog-ng
-I/usr/local/include/syslog-ng/ivykis -I/usr/local/include/eventlog
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I ./
-g -O2 -I/usr/local/include/ -o ./_x003.o -c cfuncs.cgo2.c
TERM='dumb' gcc -I /home/nsaboo/Documents/goworkspace/src/poc -fPIC -m64
-pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build
-gno-record-gcc-switches -I/usr/local/include/syslog-ng
-I/usr/local/include/syslog-ng/ivykis -I/usr/local/include/eventlog
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I ./
-g -O2 -I/usr/local/include/ -o ./_cgo_main.o -c _cgo_main.c
cd /home/nsaboo/Documents/goworkspace/src/poc
TERM='dumb' gcc -I . -fPIC -m64 -pthread -fmessage-length=0
-fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -o
$WORK/b001/_cgo_.o $WORK/b001/_cgo_main.o $WORK/b001/_x001.o
$WORK/b001/_x002.o $WORK/b001/_x003.o -g -O2 syslog-node.so
-L/usr/local/lib/ -lsyslog-ng -L/usr/local/lib/syslog-ng -ldbparser
-L/usr/local/lib -Wl,--export-dynamic -lgmodule-2.0 -pthread -lgthread-2.0
-pthread -lglib-2.0 -lsyslog-ng -lglib-2.0 -levtlog
TERM='dumb' /usr/local/go/pkg/tool/linux_amd64/cgo -dynpackage main
-dynimport $WORK/b001/_cgo_.o -dynout $WORK/b001/_cgo_import.go
cat >$WORK/b001/importcfg << 'EOF' # internal
# import config
packagefile bufio=/usr/local/go/pkg/linux_amd64/bufio.a
packagefile encoding/json=/usr/local/go/pkg/linux_amd64/encoding/json.a
packagefile fmt=/usr/local/go/pkg/linux_amd64/fmt.a
packagefile os=/usr/local/go/pkg/linux_amd64/os.a
packagefile path=/usr/local/go/pkg/linux_amd64/path.a
packagefile runtime=/usr/local/go/pkg/linux_amd64/runtime.a
packagefile time=/usr/local/go/pkg/linux_amd64/time.a
packagefile runtime/cgo=/usr/local/go/pkg/linux_amd64/runtime/cgo.a
packagefile syscall=/usr/local/go/pkg/linux_amd64/syscall.a
EOF
/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/b001/_pkg_.a -trimpath
$WORK/b001 -p main -buildid ZmTjWDq-3vSs8dJXUcwn/ZmTjWDq-3vSs8dJXUcwn
-goversion go1.12.4 -D _/home/nsaboo/Documents/goworkspace/src/poc
-importcfg $WORK/b001/importcfg -pack -c=2 $WORK/b001/_cgo_gotypes.go
$WORK/b001/main.cgo1.go $WORK/b001/cfuncs.cgo1.go $WORK/b001/_cgo_import.go
# command-line-arguments
./main.go:91:85: cannot use _Cgo_ptr(_Cfpvar_fp_callOnMeGo_cgo) (type
unsafe.Pointer) as type func(*_Ctype_char, *_Ctype_char, _Ctype_ulong,
_Ctype_int) in field value
./main.go:91:129: cannot use _Ctype_int(1) (type _Ctype_int) as type int in
field value
./main.go:166:94: cannot use _Cgo_ptr(_Cfpvar_fp_callOnMeGo_cgo) (type
unsafe.Pointer) as type func(*_Ctype_char, *_Ctype_char, _Ctype_ulong,
_Ctype_int) in field value
./main.go:166:148: type _Ctype_int is not an expression
makefile:6: recipe for target 'main' failed
make: *** [main] Error 2

On Wed, Jul 10, 2019 at 2:28 PM Tamás Gulácsi <tgulacs...@gmail.com> wrote:

> *C.foo
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/32a3a3c6-78e2-492d-9542-8a1c29deb600%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALjMrq6xBt145OtQdL4VuADL-OSv%3DN_-CSyoRkiXCQM%2BqpB49A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to