# Foreign\_archives in dune really seem to want a dll

**URL:** https://discuss.ocaml.org/t/foreign-archives-in-dune-really-seem-to-want-a-dll/11714
**Category:** Ecosystem
**Tags:** dune
**Created:** [March 20, 2023, 6:43am UTC](https://discuss.ocaml.org/t/foreign-archives-in-dune-really-seem-to-want-a-dll/11714 "2023-03-20T06:43:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![smuenzel](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/smuenzel/32/3945_2.png) [@smuenzel](https://discuss.ocaml.org/u/smuenzel)
#### Post date: [March 20, 2023, 6:43am UTC](https://discuss.ocaml.org/t/foreign-archives-in-dune-really-seem-to-want-a-dll/11714/1 "2023-03-20T06:43:08Z")

</div>

I’m trying to include my self-built library (let’s call it libx.a), but when I include it in a “foreign\_archives” stanza `(foreign_archives ../my-library/x)`, dune really wants a dynamic library “dllx.so”, in addition to the static one. I wasn’t able to convince it otherwise, even with “disable\_dynamically\_linked\_foreign\_archives”.  
Does anyone have any experience with this?

---

<div class="post-metadata">

### Author: ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)
#### Post date: [March 20, 2023, 7:40am UTC](https://discuss.ocaml.org/t/foreign-archives-in-dune-really-seem-to-want-a-dll/11714/2 "2023-03-20T07:40:16Z")

</div>

Yes, this is because a DLL is typically needed to link your library into pure bytecode executables. If you don’t care about bytecode, you can add `(modes native)` to your stanza.

Cheers,  
Nicolas

---

<div class="post-metadata">

### Author: ![smuenzel](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/smuenzel/32/3945_2.png) [@smuenzel](https://discuss.ocaml.org/u/smuenzel)
#### Post date: [March 20, 2023, 9:13am UTC](https://discuss.ocaml.org/t/foreign-archives-in-dune-really-seem-to-want-a-dll/11714/3 "2023-03-20T09:13:03Z")

</div>

Ah that’s interesting. That works when I don’t have a `ctypes` stanza, but it seems like dune ctypes requires a bytecode build

---

<div class="post-metadata">

### Author: ![emillon](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/emillon/32/1206_2.png) [@emillon](https://discuss.ocaml.org/u/emillon)
#### Post date: [March 20, 2023, 9:28am UTC](https://discuss.ocaml.org/t/foreign-archives-in-dune-really-seem-to-want-a-dll/11714/4 "2023-03-20T09:28:04Z")

</div>

`(library)` will also try to make a `cmxs` file for dynlinking, which requires a dynamic version of the foreign archive. You can disable this by adding `(no_dynlink)` to the stanza.

---

<div class="post-metadata">

### Author: ![SturdyPose](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/sturdypose/32/5686_2.png) [@SturdyPose](https://discuss.ocaml.org/u/SturdyPose)
#### Post date: [December 11, 2024, 11:49am UTC](https://discuss.ocaml.org/t/foreign-archives-in-dune-really-seem-to-want-a-dll/11714/5 "2024-12-11T11:49:37Z")

</div>

I’m also having this issue with dune 3.6 and ctypes stanza on win platform. Does ctypes stanza require dynlinked library? Is it possible to use ctypes and link it statically to the executable?
