# How to patch an opam package

**URL:** <https://discuss.ocaml.org/t/how-to-patch-an-opam-package/11209>\
**Category:** Ecosystem\
**Tags:** opam\
**Created:** [January 19, 2023, 5:26pm UTC](https://discuss.ocaml.org/t/how-to-patch-an-opam-package/11209 "2023-01-19T17:26:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frederic\_Loyer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/frederic_loyer/32/3472_2.png) [@Frederic\_Loyer](https://discuss.ocaml.org/u/Frederic_Loyer)\
**Post date:** [January 19, 2023, 5:26pm UTC](https://discuss.ocaml.org/t/how-to-patch-an-opam-package/11209/1 "2023-01-19T17:26:47Z")

</div>

On my system (Windows/Diskuv), cairo2 fails to compile. I have raised the issue which seems to be simple (just use variadic preprocessor arguments in the MSVC way), but if I modify the culprit file, `opam install cairo2` gets the package back from the cache and compile the original version.

I have tried to copy the opam directory (`cairo2.0.6.2`) and launch `opam install .` thinking opam will install the package from the current directory, but the error message indicate it uses the directory from the `opam\playground\.opam-switch\build` directory, then I can’t build a customized version.

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [January 19, 2023, 5:54pm UTC](https://discuss.ocaml.org/t/how-to-patch-an-opam-package/11209/2 "2023-01-19T17:54:41Z")

</div>

```plaintext
opam source --dev cairo2 && cd cairo2
...hack hack...
git add -p 
git commit -m "Fix MSVC"
opam pin add .

```

---

<div class="post-metadata">

**Author:** ![Frederic\_Loyer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/frederic_loyer/32/3472_2.png) [@Frederic\_Loyer](https://discuss.ocaml.org/u/Frederic_Loyer)\
**Post date:** [January 19, 2023, 6:47pm UTC](https://discuss.ocaml.org/t/how-to-patch-an-opam-package/11209/3 "2023-01-19T18:47:51Z")

</div>

I have tried it. From a `D:\DiskuvProjets\cairo2` directory, I type `opam pin add .` and get the error:

```auto
# C:\Users\frede\AppData\Local\opam\playground\.opam-switch\build\cairo2.0.6.2\_build\default\src\cairo_macros.h(178): error C2010: '.' : inattendu dans la liste de paramètres de macro

```

which indicates the cairo\_macros.h is still compiled from the private opam directory.

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [January 19, 2023, 7:13pm UTC](https://discuss.ocaml.org/t/how-to-patch-an-opam-package/11209/4 "2023-01-19T19:13:17Z")

</div>

Are you sure you commited changes to the repo ?

---

<div class="post-metadata">

**Author:** ![mseri](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mseri/32/91_2.png) [@mseri](https://discuss.ocaml.org/u/mseri)\
**Post date:** [January 19, 2023, 7:14pm UTC](https://discuss.ocaml.org/t/how-to-patch-an-opam-package/11209/5 "2023-01-19T19:14:13Z")

</div>

It should be using your sources there, if you want to make sure, try `opam pin add . --with-version 0.7`, you should see the error appear with this new version instead. Also, make sure you have committed your changes before pinning.

---

<div class="post-metadata">

**Author:** ![Frederic\_Loyer](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/frederic_loyer/32/3472_2.png) [@Frederic\_Loyer](https://discuss.ocaml.org/u/Frederic_Loyer)\
**Post date:** [January 19, 2023, 7:30pm UTC](https://discuss.ocaml.org/t/how-to-patch-an-opam-package/11209/6 "2023-01-19T19:30:58Z")

</div>

My bad… `git commit -m 'a commit message'` should be written `git commit -m "a commit message"` with a CMD prompt. Now, all is correct (excepted other issues which don’t deal with the current thread about opam).

Many thanks !

---

<div class="post-metadata">

**Author:** ![dbuenzli](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dbuenzli/32/18_2.png) [@dbuenzli](https://discuss.ocaml.org/u/dbuenzli)\
**Post date:** [January 19, 2023, 7:33pm UTC](https://discuss.ocaml.org/t/how-to-patch-an-opam-package/11209/7 "2023-01-19T19:33:51Z")

</div>

Thanks for the info I edited the post to make the instructions cross platform.

---

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [January 19, 2023, 9:43pm UTC](https://discuss.ocaml.org/t/how-to-patch-an-opam-package/11209/8 "2023-01-19T21:43:05Z")

</div>

I’ve had similar problems before, and one of the maintainers (I think kit-y-kate ?) pointed out that I should always check that there’s no pre-existing pin – and if there is, to remove it. Once I did that, my problems seem to have disappeared. Just thought I’d note it. I also always do `--working-dir` just to be sure I didn’t forget to do a commit.
