From: Julien Lepiller <julien@lepiller.eu>
To: help-guix@gnu.org, Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
Subject: Re: OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 3 - comparison with guile)
Date: Tue, 31 Dec 2024 15:57:48 +0100 [thread overview]
Message-ID: <C8879BB1-A50D-415E-B23F-FC951DE0F4AF@lepiller.eu> (raw)
In-Reply-To: <a38e5b83-ec61-4573-8e8b-0f866a5a499d@posteo.de>
I tried and after adding ocaml-findlib in the shell, I was able to build with:
ocamlfind ocamlc -package zarith -linkpkg -o main main.ml
I don't use ocaml often but it looks like how you need to specify the libraries to gcc with -I and -l.
I don't know how it would work with ocamlc alone. Does it work like that on other distros?
Le 31 décembre 2024 15:06:38 GMT+01:00, Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> a écrit :
>On 30.12.24 18:50, Zelphir Kaltstahl wrote:
>>
>> Hello Guix users,
>>
>> I am facing a problem trying to use Guix to install Ocaml packages.
>>
>> I was implementing a simple recursive factorial function, as part of learning the language, and tested what would happen, if I calculated factorial of 100 ... Result: 0. "Ah!" I thought, "all I need to do is get that Zarith package I have been reading about before, and import that in my code!". So I added it to my manifest.scm file, which I use for a `guix shell`, and expected the Ocaml compiler to naturally pick up packages installed via guix, since the Ocaml compiler ocamlc is also installed using guix. However, it seems this is dysfunctional currently and ocamlc does not realize that the library is in fact installed. I am not sure where it is looking for libraries.
>>
>> Here is how to reproduce:
>>
>> ~~~~guix-env/channels.scm~~~~
>> (list (channel
>> (name 'guix)
>> (url"https://git.savannah.gnu.org/git/guix.git")
>> (branch "master")
>> (commit
>> "4473f8ae902c2192cab6919363a9101ce9861e45")
>> (introduction
>> (make-channel-introduction
>> "9edb3f66fd807b096b48283debdcddccfea34bad"
>> (openpgp-fingerprint
>> "BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA")))))
>> ~~~~
>>
>> ~~~~guix-env/manifest.scm~~~~
>> (specifications->manifest
>> '("ocaml"
>> "ocaml-utop"
>> "dune"
>> ;; "opam" ; using guix to install packages, should not need opam
>> "bash"
>> "ocaml-zarith"))
>> ~~~~
>>
>> ~~~~main.ml~~~~
>> open Z
>>
>> let factorial n =
>> let rec iter n =
>> if n < (of_int 2)
>> then of_int 1
>> else mul n (iter (sub n (of_int 1)))
>> in
>> iter (of_int n)
>>
>>
>> let _ = 5 |> factorial |> to_string |> print_endline
>> let _ = 100 |> factorial |> to_string |> print_endline
>> ~~~~
>>
>> ~~~~command~~~~
>> guix time-machine --channels=guix-env/channels.scm -- shell --check --manifest=guix-env/manifest.scm -- bash -c 'ocamlc -c main.ml -o main.byte'
>>
>> guix shell: checking the environment variables visible from shell '/bin/bash'...
>> guix shell: All is good! The shell gets correct environment variables.
>> File "main.ml", line 1, characters 5-6:
>> 1 | open Z
>> ^
>> Error: Unbound module Z
>> ~~~~
>>
>> If ocamlc does not check locations, where guix installs ocaml libraries, then it is completely useless to install Ocaml libraries using Guix. Of course a programming language without any libraries would also be unpleasant to use for many things.
>>
>> How can I make ocamlc realize, that the library is in fact installed, that it just needs to look in the right places?
>>
>> Is this something that can be properly fixed in some dynamically created configuration of ocamlc, so that it automatically will look in the correct directories, depending on which guix shell or which guix profile it is installed in?
>>
>> Is this perhaps even a defect of ocamlc itself, having hardcoded locations where it looks for libraries?
>>
>> Do I have to tell ocamlc somehow where it is supposed to be looking? (In that case I guess it cannot be used with `guix shell`, as the directories are not predictable, and I would have to use a Guix profile.)
>>
>> Best regards,
>> Zelphir
>>
>I want to draw attention to the following:
>
>This behavior is different from what we can observe with GNU Guile. When installing libraries for Guile via GNU Guix, Guile picks them up inside guix shells and guix profiles without issues. I suspect, that the way the `ocaml` package is installed or the way `ocamlc` itself works or is built, makes the difference.
>
>Best regards,
>Zelphir
>
next prev parent reply other threads:[~2024-12-31 14:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-30 17:50 OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries Zelphir Kaltstahl
2024-12-30 17:53 ` OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 1) Zelphir Kaltstahl
2024-12-30 19:33 ` Julien Lepiller
2024-12-30 19:53 ` OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries Zelphir Kaltstahl
2024-12-31 14:02 ` OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 2 - using guix profiles) Zelphir Kaltstahl
2024-12-31 14:06 ` OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 3 - comparison with guile) Zelphir Kaltstahl
2024-12-31 14:57 ` Julien Lepiller [this message]
2025-01-02 1:18 ` Zelphir Kaltstahl
2025-01-02 7:44 ` Julien Lepiller
2025-01-02 13:35 ` Zelphir Kaltstahl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=C8879BB1-A50D-415E-B23F-FC951DE0F4AF@lepiller.eu \
--to=julien@lepiller.eu \
--cc=help-guix@gnu.org \
--cc=zelphirkaltstahl@posteo.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).