# Get include path for zig.h

**URL:** <https://ziggit.dev/t/get-include-path-for-zig-h/4007>\
**Category:** Help\
**Tags:** build-system, standard-library\
**Created:** [April 18, 2024, 7:20pm UTC](https://ziggit.dev/t/get-include-path-for-zig-h/4007 "2024-04-18T19:20:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkrieger1](https://ziggit.dev/user_avatar/ziggit.dev/mkrieger1/32/2109_2.png) [@mkrieger1](https://ziggit.dev/u/mkrieger1)\
**Post date:** [April 18, 2024, 7:20pm UTC](https://ziggit.dev/t/get-include-path-for-zig-h/4007/1 "2024-04-18T19:20:09Z")

</div>

I’m using Zig 0.11.0 and in a `build.zig` I’m trying to pass the path of the directory containing the `zig.h` shipped with Zig as include directory to an external tool, i.e. what `zig env` returns as `"lib_dir"`.

I looked into the source code of the `zig env` command and found that it uses `introspect.zig` which does not seem to be part of the standard library.

I found [Getting the zig compiler path in build.zig](https://ziggit.dev/t/getting-the-zig-compiler-path-in-build-zig/946). Do I have to manipulate the path to the Zig executable returned by `b.zig_exe` or is there a better way?

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [April 18, 2024, 8:33pm UTC](https://ziggit.dev/t/get-include-path-for-zig-h/4007/2 "2024-04-18T20:33:47Z")

</div>

You can get the zig.exe path using [std.fs.selfExeDirPath](https://ziglang.org/documentation/0.11.0/std/#A;std:fs.selfExeDirPath)  
Then call [std.fs.path.dirname](https://ziglang.org/documentation/0.11.0/std/#A;std:fs.path.dirname) to remove the `bin` part.  
Finally call [std.fs.path.join](https://ziglang.org/documentation/0.11.0/std/#A;std:fs.path.join) to add `lib`.

---

<div class="post-metadata">

**Author:** ![nyc](https://ziggit.dev/user_avatar/ziggit.dev/nyc/32/1167_2.png) [@nyc](https://ziggit.dev/u/nyc)\
**Post date:** [April 18, 2024, 11:21pm UTC](https://ziggit.dev/t/get-include-path-for-zig-h/4007/3 "2024-04-18T23:21:03Z")

</div>

do you mean getSelfExePath? (that’s where your link goes)  
and the docs give this advice.

```zig
 If you only need the directory, use selfExeDirPath

```

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [April 19, 2024, 6:26am UTC](https://ziggit.dev/t/get-include-path-for-zig-h/4007/4 "2024-04-19T06:26:45Z")

</div>

Thank you. I meant `selfExeDirPath`.

---

<div class="post-metadata">

**Author:** ![mkrieger1](https://ziggit.dev/user_avatar/ziggit.dev/mkrieger1/32/2109_2.png) [@mkrieger1](https://ziggit.dev/u/mkrieger1)\
**Post date:** [April 19, 2024, 9:14am UTC](https://ziggit.dev/t/get-include-path-for-zig-h/4007/5 "2024-04-19T09:14:03Z")

</div>

The `std.fs.selfExe[…]` family of functions is not what I need here, they refer to the executable that is executing the build (the result of compiling `build.zig`), somewhere in `zig-cache/o/…`, not the `zig` executable itself.

It seems `b.zig_exe` and then replacing the trailing `/zig` with `/lib` is indeed the way to go.
