# Install C headers for C library

**URL:** <https://discuss.ocaml.org/t/install-c-headers-for-c-library/13405>\
**Category:** Learning\
**Tags:** coq, c, header, install, dune\
**Created:** [November 11, 2023, 3:07pm UTC](https://discuss.ocaml.org/t/install-c-headers-for-c-library/13405 "2023-11-11T15:07:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_II](https://avatars.discourse-cdn.com/v4/letter/_/7993a0/32.png) [@\_II](https://discuss.ocaml.org/u/_II)\
**Post date:** [November 11, 2023, 3:08pm UTC](https://discuss.ocaml.org/t/install-c-headers-for-c-library/13405/1 "2023-11-11T15:08:00Z")

</div>

Hello,

In my setup, I have Coq extract to OCaml which I then compile as a C library with the following setup:

```auto
(coq.extraction
 (prelude bitflip)
 (extracted_modules bitflip))

(executable
 (name CAPI)
 (foreign_stubs (language c)
                (names cstub))
 (flags :standard -linkall)
 (modes (native shared_object))
 (modules bitflip CAPI))

(install
 (section lib)
 (files
  (CAPI.so as libbitflip.so)
  (cstub.h as bitflip.h)))

```

The directory tree is

```auto
dune-project
src
├─ bitflip.v
├─ CAPI.ml
├─ cstub.c
├─ cstub.h
├─ dune

```

I’m new to OCaml, opam, and dune and it’s hard for me to understand everything that is going on. In any case, my problem is that the install stanza sends `bitflip.h` to `/usr/local/lib/bitflip.h` which is obviously the wrong directory for it to be in.

The advice on the stanza reference is to use `public_headers` to install C headers, but that is for a `library` stanza. However, what I found for creating a shared library was using the `executable` stanza with `(modes (shared_object))`.

I would appreciate advice on this.

---

<div class="post-metadata">

**Author:** ![\_II](https://avatars.discourse-cdn.com/v4/letter/_/7993a0/32.png) [@\_II](https://discuss.ocaml.org/u/_II)\
**Post date:** [November 13, 2023, 5:02am UTC](https://discuss.ocaml.org/t/install-c-headers-for-c-library/13405/2 "2023-11-13T05:02:01Z")

</div>

After reading more of the Dune documentation, I am now getting some ideas on how to accomplish this. I will update this thread with a solution soon.

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [November 13, 2023, 10:57am UTC](https://discuss.ocaml.org/t/install-c-headers-for-c-library/13405/3 "2023-11-13T10:57:24Z")

</div>

Apologies for not digging into the concrete problem you’re facing, and it seems different from my problem, but maybe this helps someone. I had trouble passing the include and library object paths to the c compiler and linker for FFI bindings (here for cuda). The following worked:

```plaintext
(env
 (_
  (c_flags -I /usr/local/cuda/include)
  (link_flags -cclib -L/usr/local/cuda/lib64/stubs)))

(ctypes
 (build_flags_resolver
  (vendored (c_library_flags -I /usr/local/cuda/include -L /usr/local/cuda/lib64/stubs))))

```

(unrelated entries omitted). Downside is I’m hardcoding the paths…
