Thread overview
Dub option for specifying importC include paths
Sep 13, 2023
Ben Jones
3 days ago
Sergey
3 days ago
jmh530
3 days ago
Emmanuel
2 days ago
jmh530
2 days ago
jmh530
1 day ago
JEmmanuel
3 days 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

3 days 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

3 days 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.

3 days 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

3 days 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!

2 days 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

2 days ago

On Wednesday, 1 October 2025 at 23:03:10 UTC, jmh530 wrote:

>

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

As kinke pointed out on the issue, when a prior bug got fixed a test was added that covers this. I would suggest borrowing that for the example.

1 day ago

On Thursday, 2 October 2025 at 18:49:51 UTC, jmh530 wrote:

>

On Wednesday, 1 October 2025 at 23:03:10 UTC, jmh530 wrote:

>

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

As kinke pointed out on the issue, when a prior bug got fixed a test was added that covers this. I would suggest borrowing that for the example.

Alright noted!