Thread overview
Dub option for specifying importC include paths
Sep 13, 2023
Ben Jones
20 hours ago
Sergey
16 hours ago
jmh530
11 hours ago
Emmanuel
7 hours ago
jmh530
17 hours ago
kinke
September 13, 2023

I'm trying to build a wrapper around a lib written in C by having importC compile the .c files, and then providing a nice D API on top. My dub config file seems to be finding the C files to compile without issue, but it's not passing the include dirs for the preprocessor to find headers. Is there an option I'm missing or is there some way to get DUB to do this for me aside from passing like -cpp flags via dflags?

From my dub.json:

    "cSourcePaths": [
        "source/libgit2/src/",
        "source/libgit2/src/util/"
    ],
    "cImportPaths" : [
        "source/libgit2/src/util/",
        "source/libgit2/src/libgit2/"
    ],
    "importPaths" : [
        "source/libgit2/src/util/",
    ],

    "excludedSourceFiles" : [
        "source/libgit2/src/cli/*.c"
    ],

And the what dub's actually running when it preprocesses the first .c file:

/usr/bin/cc -fno-blocks -dD -Wno-builtin-macro-redefined -E -include /opt/homebrew/Cellar/ldc/1.34.0/include/dlang/ldc/importc.h source/libgit2/src/libgit2/annotated_commit.c -o /var/folders/p3/6fcprxgn0xb77hzb031vm1_m0000gn/T/itmp-ldc-de8fa3/annotated_commit.i

Which has doesn't specify any -I flags

20 hours ago

On Wednesday, 13 September 2023 at 22:48:01 UTC, Ben Jones wrote:

>

I'm trying to build a wrapper around a lib written in C by having importC compile the .c files, and then providing a nice

Real world example from ImportC inventors or DUB maintainers would be great to have.
Thanks

17 hours ago

On Wednesday, 13 September 2023 at 22:48:01 UTC, Ben Jones wrote:

>

Which has doesn't specify any -I flags

This should have been fixed by https://github.com/dlang/dub/pull/2818, so make sure you use a recent dub version.

16 hours ago

On Wednesday, 1 October 2025 at 10:07:48 UTC, Sergey wrote:

>

On Wednesday, 13 September 2023 at 22:48:01 UTC, Ben Jones wrote:

>

I'm trying to build a wrapper around a lib written in C by having importC compile the .c files, and then providing a nice

Real world example from ImportC inventors or DUB maintainers would be great to have.
Thanks

Filed issue
https://github.com/dlang/dub/issues/3075

11 hours ago

On Wednesday, 1 October 2025 at 14:36:13 UTC, jmh530 wrote:

>

On Wednesday, 1 October 2025 at 10:07:48 UTC, Sergey wrote:

>

On Wednesday, 13 September 2023 at 22:48:01 UTC, Ben Jones wrote:

>

I'm trying to build a wrapper around a lib written in C by having importC compile the .c files, and then providing a nice

Real world example from ImportC inventors or DUB maintainers would be great to have.
Thanks

Filed issue
https://github.com/dlang/dub/issues/3075

Actually planning to take this on for SAoC. I don't know how possible that would be.

Thanks!

7 hours ago

On Wednesday, 1 October 2025 at 19:02:26 UTC, Emmanuel wrote:

>

Actually planning to take this on for SAoC. I don't know how possible that would be.

Thanks!

I wouldn’t go too crazy. There’s a folder with simple examples already [1]. I would just do something with a simple C function that gets called in a D project (and the C function is in a separate sub folder).

[1] https://github.com/dlang/dub/tree/master/examples