How to use Opam to compile a package that doesn't with Opam but does with make

How can I ask Opam to compile a package that compiles manually with make but does not with the current opam file ?

I would like to use cpdf 2.2.1 while I’m using Ocaml 4.07.1

$ opam install cpdf
The following dependencies couldn't be met:
- cpdf → camlpdf < 2.1 → ocaml < 4.03.0
base of this switch (use `--unlock-base' to force)
- cpdf → ocaml < 4.06.0
base of this switch (use `--unlock-base' to force)

While on :


camlpdf.2.2.1 can be installed on a 4.07.1 switch.

I’ve tried --unlock-base and got that message from opam:

$ opam install --unlock-base cpdf
[ERROR] Sorry, resolution of the request timed out.
Try to specify a simpler request, use a different solver, or increase the allowed time by setting OPAMSOLVERTIMEOUT to a
bigger value (currently, it is set to 60.0 seconds).

I didn’t change the value of the variable OPAMSOLVERTIMEOUT before asking this question.

The author of the package says that it’s possible to manually install camlpdf and cpdf (2.2.1) from source with Ocaml 4.07.1:

 $ make install  # for camlpdf
 $ make # for cpdf
 # with the same version for both (2.2.1)

Hence the question: how can I ask Opam to install cpdf.2.2.1 with OCaml 4.07.1?
Should I modify the local opam file?

1 Like

You can use the —edit flag when calling opam install (if I remember correctly) to edit the local opam file and install the package.

A PR to the opam repository with the updated bound would be great, I can make one later if you don’t have time

Meanwhile, cpdf 2.3 is being released:

I tried to do
opam pin add git+
But I got an error message:

[ERROR] Could not synchronize ~/.opam/4.07.1_ocsigen/.opam-switch/sources/cpdf from
        "/usr/bin/git fetch -q +2.3:refs/remotes/opam-ref-2.3" exited with code
        128 "fatal: Couldn't find remote ref 2.3"
[ERROR] Error getting source from git+
          - git+

Then with #v2.3, but it pins 2.2.1:

$ opam pin add cpdf
[cpdf.2.2.1] synchronised from git+
cpdf is now pinned to git+ (version 2.2.1)

The following dependencies couldn't be met:
  - cpdf → ocaml < 4.06.0
      base of this switch (use `--unlock-base' to force)

[NOTE] Pinning command successful, but your installed packages may be out of sync.

Which path is it supposed to be to get cpdf.2.3?

I didn’t find the --edit option in the opam install section. I saw --ignore-constraints-on.

That is surprising. It should ask you to overwrite the opam file using the new one. We mergend cpdf 2.3 and there is a PR to relax cpdf 2.2.1 bounds. You can modify the local opam file, or opam update and then install the new cpdf

I’m finding opam’s dependency resolution confusing here. The linked opam file says "camlpdf" {>= "2.2.1"}. So why is opam install cpdf saying:

- cpdf → camlpdf < 2.1 → ocaml < 4.03.0`

It seems to be resolving to a version explicitly forbidden by the version bound.

1 Like

The edit option is available for opam pin command, used directly opam pin edit cpdf or used as an argument opam pin --edit cpdf <url> (cf. manpage).

The repo url format is described here, the # is a separator to specify a branche, tag or hash. As git reference 2.3 don’t exist on cpdf repo, it can’t succeed, but tag v2.3 exists and it is retrieved then.

opam tries to find by different means an opam file to follow. As cpdf repo doesn’t contain one, and no version is specified on cli, it takes as opam file for pinning the last one in the repository, i.e. 2.2.1 one.

But as said @mseri, the easiest solution for you, is to update opam repositories (opam update) and reinstall cpdf (2.3 is on opam repo & no more have the ocaml.4.06.0 constraint).

I could do opam update && opam upgrade && opam install cpdf .
In fact, I searched in opam install --help (and opam --help ), thinking all commands were shown there.
But it’s specifically located in opam pin --help (or opam pin edit --help )

Thanks for your explanation.

I’ve been trapped with “silently” (forgotten) pinned packages:

  • cpdf was pinned to git+ but this is not visible with opam list
  • another package that I could hardly notice because version is in blue instead of purple (may be light blue background could be more visible?)

What about modifying the opam list command so:
1/ it indicates the switch name in a header
2/ it produces the details of pinned packages in a footer
opam list could be an alias for:

  • header: opam switch show
  • body: opam list
  • footer: opam pin list

This is what I quickly set up:
alias 'opaml'='opam switch show && opam list && opam list --pinned'

Now I know, but this could be helpful for beginners (Ocaml, Emacs/Vim, Merlin, Opam, Dune… : that’s a lot of stuff to handle at the same time).

In fact, I searched in opam install --help (and opam --help ), thinking all commands were shown there.

Each command have its own help/manpage with all its options/subcommands.