Skip to content

Zig errors on not finding c header files, but works if the include path parameter is after --mod param in cli #18469

@akhildevelops

Description

@akhildevelops

Zig Version

0.12.0-dev.2059+42389cb9c

Steps to Reproduce and Observed Behavior

While running below test command (that's the default test command created by buiild_runner), there's a compiler error on not finding header files.

/home/akhil/.config/Code/User/globalStorage/ziglang.vscode-zig/zig_install/zig test \
    -lcuda -lnvrtc \
    -I /usr/local/cuda/include -L /usr/local/cuda/lib64 \
    --dep cudaz --mod root /home/akhil/practice/cudaz/test/general.zig \
    --mod cudaz /home/akhil/practice/cudaz/src/lib.zig \
    -lc \
    --cache-dir /home/akhil/practice/cudaz/zig-cache --global-cache-dir /home/akhil/.cache/zig \
    --name test

Output:

src/c.zig:1:18: error: C import failed
pub const cuda = @cImport({
                 ^~~~~~~~
referenced by:
    cuda: src/error.zig:5:15
    CudaErrorEnum: src/error.zig:10:47
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
/home/akhil/practice/cudaz/zig-cache/o/d41127f1c4e1cd6955c7dad1694f4c1c/cimport.h:1:10: error: 'cuda.h' file not found
#include <cuda.h>
         ^
src/c.zig:7:19: error: C import failed
pub const nvrtc = @cImport(@cInclude("nvrtc.h"));
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/akhil/practice/cudaz/zig-cache/o/841287f7c59616b0e1de04edb366cdad/cimport.h:1:10: error: 'nvrtc.h' file not found
#include <nvrtc.h>

If -I /usr/local/cuda/include is rearanged then zig compiles and runs the test successfully

/home/akhil/.config/Code/User/globalStorage/ziglang.vscode-zig/zig_install/zig test \
    -lcuda -lnvrtc \
    -L /usr/local/cuda/lib64 \
    --dep cudaz --mod root /home/akhil/practice/cudaz/test/general.zig \
    -I /usr/local/cuda/include \
    --mod cudaz /home/akhil/practice/cudaz/src/lib.zig \
    -lc \
    --cache-dir /home/akhil/practice/cudaz/zig-cache --global-cache-dir /home/akhil/.cache/zig \
    --name test

Output:

All 8 tests passed.

Expected Behavior

Test should run without compile errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions