I am calling golang with c, I want to return a string array and a int array, I do it like this:
package main
import "C"
//export Seg
func Seg(input *C.char, segs *[]*C.char, tags *[]int) (errChars *C.char) {
count := 10
segs_ := make([]*C.char, 10, 10)
for i:=0; i<count; i++ {
segs_[i] = C.CString("aaaaaa")
}
segs = &segs_
tags_ := make([]int, count)
for i:=0; i<count; i++ {
tags_[i] = i
}
tags = &tags_
return
}
func main() {}
Build with
go build -o libacrf.so -buildmode=c-shared clib.go
call it like this:
#include <stdio.h>
#include <stdlib.h>
#include "libacrf.h"
int main(int argc, char *argv[])
{
GoSlice *segs, *tags;
char* err;
err = Seg("hahahhaha", segs, tags);
if (err != NULL) {
fprintf(stderr, "error: %s\n", err);
free(err);
return 1;
}
printf("%llu\n", (*tags).len); // it should be 10, but it is not right now
return 0;
}
But the problem is that I can not get the real result from golang.