I tried using cgo to write a small wrapper for the x264 library and ran into a problem with nested structures. The library uses many complex structures in which some of the fields are anonymous structures.
When I try to use cgo to access these structures, I run compilation errors because go claims that nested structures do not exist.
I managed to collapse the problem into a .h file and a .go file inserted below. Hope this is clear enough to show the problem.
Does anyone know a solution or workaround for this problem?
Thanks.
struct.h
typedef struct param_struct_t {
int a;
int b;
struct {
int c;
int d;
} anon;
int e;
struct {
int f;
int g;
} anon2;
} param_struct_t;
main.go
package main
import "C"
import (
"fmt"
)
func main() {
var param C.param_struct_t
fmt.Println(param.a)
fmt.Println(param.b)
fmt.Println(param.c)
fmt.Println(param.d)
fmt.Printf("%#v", param)
}
source
share