# Clang.jl wrapper generation warnings/missing parts

**URL:** <https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093>\
**Category:** General Usage\
**Tags:** c, clang\
**Created:** [February 2, 2020, 8:39pm UTC](https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093 "2020-02-02T20:39:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rayegun](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rayegun/32/26729_2.png) [@rayegun](https://discourse.julialang.org/u/rayegun)\
**Post date:** [February 2, 2020, 8:39pm UTC](https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093/1 "2020-02-02T20:39:44Z")

</div>

I’m trying to wrap this this [GraphBLAS.h](https://github.com/sergiud/SuiteSparse/blob/master/GraphBLAS/Include/GraphBLAS.h) file using Clang.jl (There is already a wrapper package, but I want to try generating it automatically). I used this code:

```julia
const z = "/usr/lib/clang/9.0.0/include"
const y = "/home/Wimmerer/Desktop/GraphBLAS-3.1.1/Include/GraphBLAS.h"
wc = init(;headers= [y], output_file=joinpath(@ __DIR__ ,"libGB_api.jl"),common_file = joinpath(@ __DIR__ ,"libGB_common.jl"),clang_includes = vcat([y],[z]), header_wrapped = (root,current)->root == current,header_library = x->"libGB",clang_diagnostics = true)
run(wc)

```

Unfortunately while I get most ordinary functions wrapped I do have quite a few warnings and missing bits. In particular I get:

```julia
┌ Warning: not wrapping CLCursor (CLLastPreprocessing) stdio.h
└ @ Clang ~/.julia/packages/Clang/CiPzM/src/wrap_c.jl:443

```

for all the standard libs required by GraphBLAS: errno, string, stdlib, stdbool, stdint, inttypes, stddef, limits, math, stdarg

```julia
┌ Warning: not wrapping CLCursor (CLMacroInstantiation) bool
└ @ Clang ~/.julia/packages/Clang/CiPzM/src/wrap_c.jl:443

```

Repeated many times for bool, as well as `GxB_NTHREADS`, and `GxB_CHUNK `  
And finally:

```julia
┌ Warning: not wrapping CLCursor (CLVarDecl) GrB_BOOL
└ @ Clang ~/.julia/packages/Clang/CiPzM/src/wrap_c.jl:443

```

for everything under the `extern` keyword in the .h file.

I’m not well versed enough in C programming and linking to external libraries to diagnose these issues myself unfortunately. I would appreciate any pointers here!  
The Clang.jl docs have a great example, but not much to go off of if it doesn’t map well to my particular problems.

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [February 3, 2020, 12:01pm UTC](https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093/2 "2020-02-03T12:01:18Z")

</div>

Not all of the code in the header file are useful for generating Julia wrapper. It’s very tricky to handle macros correctly. For now, Clang.jl only provides _partially_ support for those “constant definition macros” such as `#define GxB_IMPLEMENTATION_NAME "SuiteSparse:GraphBLAS"`. Many of those warnings can be safely ignored. If you’re wrapping some C headers with “weird” macros, it’s inevitable to fix those macros manually.

It looks like many new users are quite confused by those warnings, maybe it’s not a good idea to explicitly warn everything.

[https://github.com/JuliaInterop/Clang.jl/pull/251](https://github.com/JuliaInterop/Clang.jl/pull/251)

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [February 3, 2020, 12:10pm UTC](https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093/3 "2020-02-03T12:10:27Z")

</div>

> [@rayegun](#):
>
> ┌ Warning: not wrapping CLCursor (CLLastPreprocessing) stdio.h └ @ Clang ~/.julia/packages/Clang/CiPzM/src/wrap\_c.jl:443

This warning is for `#include stdio.h`. We don’t need to do anything to handle it.

> [@rayegun](#):
>
> ┌ Warning: not wrapping CLCursor (CLMacroInstantiation) bool └ @ Clang ~/.julia/packages/Clang/CiPzM/src/wrap\_c.jl:443

IIRC, those macro `CLMacroInstantiation`s have already been automatically expanded. No special handling is needed here. But I’m not sure whether all kinds of the `CLMacroInstantiation`s can be safely ignored or not.

> [@rayegun](#):
>
> ┌ Warning: not wrapping CLCursor (CLVarDecl) GrB\_BOOL └ @ Clang ~/.julia/packages/Clang/CiPzM/src/wrap\_c.jl:443

Actually, those externs are not used anywhere in the APIs.

---

<div class="post-metadata">

**Author:** ![rayegun](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rayegun/32/26729_2.png) [@rayegun](https://discourse.julialang.org/u/rayegun)\
**Post date:** [February 3, 2020, 12:31pm UTC](https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093/4 "2020-02-03T12:31:20Z")

</div>

I’ll run some tests, all the core functions seem present!

> Actually, those externs are not used anywhere in the APIs.

In the GraphBLAS API? They’re supposed to be built-in’s to make using various semirings easier to use. Although in the other wrappers I’ve seen, including Python, I’m a bit confused. All of them seem to use just uninitialized classes, just something like `GxB_MIN_FIRST_INT8 = GrB_Semiring()` for instance. How is the library figuring out which semiring this actually is? By constant name?

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [February 3, 2020, 12:45pm UTC](https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093/5 "2020-02-03T12:45:58Z")

</div>

I was thinking they’re just global variables. I’m wondering what should be generated for those globals, [`cglobal`](https://docs.julialang.org/en/latest/base/c/#Core.Intrinsics.cglobal)s?

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [February 3, 2020, 1:23pm UTC](https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093/6 "2020-02-03T13:23:54Z")

</div>

> [@rayegun](#):
>
> I’m a bit confused. All of them seem to use just uninitialized classes, just something like `GxB_MIN_FIRST_INT8 = GrB_Semiring()` for instance. How is the library figuring out which semiring this actually is? By constant name?

Not sure, I’m reading [GraphBLAS\_API\_C\_1.2.0.pdf](https://github.com/tgmattso/GraphBLAS/blob/master/GraphBLAS_API_C_1.2.0.pdf) now. From chapter 2.4 and 4.2.15, it looks like those semirings can firstly be declared as opaque handles and then be defined by calling `Grb_semiring_new` function.

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [February 3, 2020, 1:28pm UTC](https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093/7 "2020-02-03T13:28:26Z")

</div>

I also noticed GraphBLAS use new C99 features like:

[https://github.com/sergiud/SuiteSparse/blob/6a80a5aa17c3d6c11224b2d24cc28c7833b66408/GraphBLAS/Include/GraphBLAS.h#L2729-L2758](https://github.com/sergiud/SuiteSparse/blob/6a80a5aa17c3d6c11224b2d24cc28c7833b66408/GraphBLAS/Include/GraphBLAS.h#L2729-L2758)

Clang.jl cannot handle this, but I guess it’s easy to rewrite these macros as pure Julia macro since Julia macro supports overloading and multiple dispatch.

---

<div class="post-metadata">

**Author:** ![rayegun](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rayegun/32/26729_2.png) [@rayegun](https://discourse.julialang.org/u/rayegun)\
**Post date:** [February 3, 2020, 2:22pm UTC](https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093/8 "2020-02-03T14:22:52Z")

</div>

Can you use dlsym for those functions? Just `dlsym(libgb,"GrB_Matrix_setElement_"*TYPE)`?

For the built-ins I think cglobal and dlsym should work right? `GrB_Semiring_new` can be used to make new semirings. But for the built in operators/monoids/semirings/types, which is what I primarily care about? I’ll test when I get home today, but to my mind that should work. Unless you can’t use dlsym with Clang.jl wrappers, although I don’t see why that would be.

So I would somehow need to check which functions/globals are missing, then load them with dlsym. That seems simple enough!

---

<div class="post-metadata">

**Author:** ![abhinav\_mehndiratta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhinav_mehndiratta/32/7924_2.png) [@abhinav\_mehndiratta](https://discourse.julialang.org/u/abhinav_mehndiratta)\
**Post date:** [March 3, 2020, 7:10pm UTC](https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093/9 "2020-03-03T19:10:52Z")

</div>

Hey ! You could try [GitHub - JuliaSparse/SuiteSparseGraphBLAS.jl: Sparse, General Linear Algebra for Graphs!](https://github.com/abhinavmehndiratta/SuiteSparseGraphBLAS.jl) . I wrote the wrapper last summer as part of GSoC, user-defined types are not supported but the rest works fine.

---

<div class="post-metadata">

**Author:** ![DrTimothyAldenDavis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drtimothyaldendavis/32/20731_2.png) [@DrTimothyAldenDavis](https://discourse.julialang.org/u/DrTimothyAldenDavis)\
**Post date:** [January 2, 2021, 10:29pm UTC](https://discourse.julialang.org/t/clang-jl-wrapper-generation-warnings-missing-parts/34093/10 "2021-01-02T22:29:25Z")

</div>

GxB\_MIN\_FIRST\_INT8 and the like are predefined objects. That one is a semiring, and you can use it without having to do GrB\_Semiring\_new. GraphBLAS has 100s of builtin operators (GrB\_PLUS\_FP64 does x+y for two doubles, for example) and 1000s of built-in semirings.
