Wrapping a recursive struct with Clang.jl

KajWiik
Wed, 03 Jun 2020 15:22:48 +0000
General Usage

I am trying to wrap a C library containing several recursive structs like this:

struct B;

typedef struct A {
  int foo;
  struct B *b;
} A;

typedef struct B {
  int faa;
  A *a;
} B;

produces wrapper like this

# Automatically generated using Clang.jl

struct A
    foo::Cint
    b::Ptr{B}
end

struct B
    faa::Cint
    a::Ptr{A}
end

which (of course) gives an error message like

ERROR: LoadError: UndefVarError: B not defined

Here’s a short test setup for Clang.jl:

using Clang

const HEADERS = ["recursive.h"]

wc = init(; headers = HEADERS,
          output_file = joinpath(@__DIR__, "test_api.jl"),
          common_file = joinpath(@__DIR__, "test_common.jl"),
          clang_includes = [CLANG_INCLUDE],
          clang_args = [""],
          header_wrapped = (root, current)->root == current,
          header_library = x->"libtest",
          clang_diagnostics = true,
          )
run(wc)

Is there any (easy) way to get these structs working?

2 posts - 2 participants