all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries
@ 2024-12-30 17:50 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-31 14:06 ` OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 3 - comparison with guile) Zelphir Kaltstahl
  0 siblings, 2 replies; 10+ messages in thread
From: Zelphir Kaltstahl @ 2024-12-30 17:50 UTC (permalink / raw)
  To: help-guix

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

-- 
repositories:https://notabug.org/ZelphirKaltstahl,https://codeberg.org/ZelphirKaltstahl

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 1)
  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 ` Zelphir Kaltstahl
  2024-12-30 19:33   ` Julien Lepiller
  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
  1 sibling, 2 replies; 10+ messages in thread
From: Zelphir Kaltstahl @ 2024-12-30 17:53 UTC (permalink / raw)
  Cc: help-guix

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
> ~~~~

I would also like to add, that utop _does_ pick up the library and that in utop 
I can:

~~~~in utop~~~~
#require "zarith";;
~~~~

And work with its functions.

So this really seems to be about ocamlc.

-- 
repositories:https://notabug.org/ZelphirKaltstahl,https://codeberg.org/ZelphirKaltstahl

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 1)
  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
  1 sibling, 1 reply; 10+ messages in thread
From: Julien Lepiller @ 2024-12-30 19:33 UTC (permalink / raw)
  To: help-guix, Zelphir Kaltstahl; +Cc: help-guix

That might be a mismatch between ocaml (latest version is ocaml 5) and tge libraries which are currently built with ocaml4. If you try the same with ocaml@4, does it work?

Le 30 décembre 2024 18:53:06 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
>> ~~~~
>
>I would also like to add, that utop _does_ pick up the library and that in utop I can:
>
>~~~~in utop~~~~
>#require "zarith";;
>~~~~
>
>And work with its functions.
>
>So this really seems to be about ocamlc.
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries
  2024-12-30 19:33   ` Julien Lepiller
@ 2024-12-30 19:53     ` Zelphir Kaltstahl
  0 siblings, 0 replies; 10+ messages in thread
From: Zelphir Kaltstahl @ 2024-12-30 19:53 UTC (permalink / raw)
  To: Julien Lepiller; +Cc: help-guix

On 30.12.24 20:33, Julien Lepiller wrote:
> That might be a mismatch between ocaml (latest version is ocaml 5) and tge libraries which are currently built with ocaml4. If you try the same with ocaml@4, does it work?

Hi Julien!

If I try with the following manifest.scm:

~~~~manifest.scm~~~~ (specifications->manifest '("ocaml@4" "ocaml-utop" "dune" 
;; "opam" "bash" "ocaml-zarith")) ~~~~

I get:

~~~~output~~~~ guix shell: warning: ambiguous package specification `ocaml@4' 
guix shell: warning: choosing ocaml@4.14.1 from gnu/packages/ocaml.scm:256:2 The 
following derivation will be built: 
/gnu/store/qzxdn126savzdn3a9ayhy3fgkl79r1y6-profile.drv building CA certificate 
bundle... listing Emacs sub-directories... building fonts directory... building 
directory of Info manuals... building profile with 5 packages... 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 ~~~~

So I tried with `ocaml@4.14.1` instead, which according to the warning it chose 
anyway, due to @4 being ambiguous, but the error remains.

Regards,
Zelphir

-- 
repositories:https://notabug.org/ZelphirKaltstahl,https://codeberg.org/ZelphirKaltstahl

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 2 - using guix profiles)
  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-31 14:02   ` Zelphir Kaltstahl
  1 sibling, 0 replies; 10+ messages in thread
From: Zelphir Kaltstahl @ 2024-12-31 14:02 UTC (permalink / raw)
  Cc: help-guix

On 30.12.24 18:53, Zelphir Kaltstahl wrote:
> 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
>> ~~~~
>
> I would also like to add, that utop _does_ pick up the library and that in 
> utop I can:
>
> ~~~~in utop~~~~
> #require "zarith";;
> ~~~~
>
> And work with its functions.
>
> So this really seems to be about ocamlc.
>
Update:

I tried using guix profiles, hoping, that with profiles and a predictable path 
(and PATH) things would be different.

Here is my setup.

~~~~guix-env/manifest.scm~~~~
(specifications->manifest
  '("emacs"

    ;; PROGRAMMING LANGUAGE - OCAML
    "ocaml@4.14.1"
    "ocaml-utop"
    "dune"
    ;; "opam"
    "ocaml-zarith"

    ... (more packages) ...
    ))
~~~~

~~~~guix-env/channels.scm~~~~
(list (channel
        (name 'guix)
        (url"https://git.savannah.gnu.org/git/guix.git")
        (branch "master")
        (commit
         "c302b7a5966908b3a5db1ef3ccd3af460b847675")
        (introduction
         (make-channel-introduction
          "9edb3f66fd807b096b48283debdcddccfea34bad"
          (openpgp-fingerprint
           "BBB0 2DDF 2CEA F6A8 0D1D  E643 A2A0 6DF2 A33A 54FA")))))
~~~~

~~~~command creating guix profile~~~~
$ GUIX_PROFILE="/home/user/dev/ocaml/ocaml-examples/book-ocaml-programming/guix-profile"

$ echo $GUIX_PROFILE
/home/xiaolong/dev/ocaml/ocaml-examples/book-ocaml-programming/guix-profile

$ GUIX_PROFILE="${GUIX_PROFILE}" guix time-machine --channels=guix-env/channels.scm -- package --manifest=guix-env/manifest.scm --profile=guix-profile
guix package: warning: Consider running 'guix pull' followed by
'guix package -u' to get up-to-date packages and security updates.

The following packages will be installed:
    ... (more packages) ...
    dune                      3.11.0
    emacs                     29.4
    ... (more packages) ...
    ocaml                     4.14.1
    ocaml-utop                2.10.0
    ocaml-zarith              1.12
    ... (more packages) ...

hint: Consider setting the necessary environment variables by running:

      GUIX_PROFILE="/home/user/dev/ocaml/ocaml-examples/book-ocaml-programming/guix-profile"
      . "$GUIX_PROFILE/etc/profile"

Alternately, see `guix package --search-paths -p "/home/user/dev/ocaml/ocaml-examples/book-ocaml-programming/guix-profile"'.
~~~~

~~~~command activating guix profile
$ GUIX_PROFILE="/home/user/dev/ocaml/ocaml-examples/book-ocaml-programming/guix-profile"

$ . "$GUIX_PROFILE/etc/profile"

$ command -V ocaml
ocaml is /home/user/dev/ocaml/ocaml-examples/book-ocaml-programming/guix-profile/bin/ocaml

$ command -V ocamlc
ocamlc is /home/user/dev/ocaml/ocaml-examples/book-ocaml-programming/guix-profile/bin/ocamlc
~~~~

~~~~command running ocaml after activating guix profile~~~~
$ ocamlc -o ex-006-functions/main2.byte ex-006-functions/main2.ml
File "ex-006-functions/main2.ml", line 1, characters 5-6:
1 | open Z
          ^
Error: Unbound module Z
~~~~

So it even with guix profile it does not work and there is no difference in the 
error when using guix shell and guix profile.

This makes me wonder then, how anyone is using any guix package that is named 
`ocaml-...`. `ocamlc` does not pick them up, so they seem unusable, unless one 
uses REPL workflow with utop. But in my opinion REPL workflow, while nice when 
familiar with it, is still not a replacement for having the compiler work 
correctly with installed libraries.

I am for now at a loss how to proceed, except for postponing the usage of 
libraries not part of the Ocaml distribution entirely. But sooner or later this 
will come up and then I will be screwed.

What I would like to have as a result at the end is a Makefile, that takes care 
of all the guix incantations, so that I don't have to construct long commands by 
hand or must rely on command history (happens that I work on another machine for 
example). This Makefile should simply activate (source) the guix profile, 
compile the code (impossible due to the described issue) and run the compiled file.

Of course I would like to benefit from the reproducible nature of having a guix 
shell or guix profile. That is why I am even doing all this in the first place. 
Any machine with working guix package manager I use, I should be able to run the 
code on in a convenient way, not wanting to setup all the tooling over and over 
again, and being sure, that I will get reproducible results.

Best regards,
Zelphir

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 3 - comparison with guile)
  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-31 14:06 ` Zelphir Kaltstahl
  2024-12-31 14:57   ` Julien Lepiller
  1 sibling, 1 reply; 10+ messages in thread
From: Zelphir Kaltstahl @ 2024-12-31 14:06 UTC (permalink / raw)
  Cc: help-guix

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

-- 
repositories:https://notabug.org/ZelphirKaltstahl,https://codeberg.org/ZelphirKaltstahl

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 3 - comparison with guile)
  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
  2025-01-02  1:18     ` Zelphir Kaltstahl
  0 siblings, 1 reply; 10+ messages in thread
From: Julien Lepiller @ 2024-12-31 14:57 UTC (permalink / raw)
  To: help-guix, Zelphir Kaltstahl

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
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 3 - comparison with guile)
  2024-12-31 14:57   ` Julien Lepiller
@ 2025-01-02  1:18     ` Zelphir Kaltstahl
  2025-01-02  7:44       ` Julien Lepiller
  0 siblings, 1 reply; 10+ messages in thread
From: Zelphir Kaltstahl @ 2025-01-02  1:18 UTC (permalink / raw)
  To: Julien Lepiller; +Cc: help-guix

On 31.12.24 15:57, Julien Lepiller wrote:
> 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?

Hi Julien!

Thank you for figuring this out! It works for me as well.

May I ask, how you found out about this?

Best regards, Zelphir

-- 
repositories:https://notabug.org/ZelphirKaltstahl,https://codeberg.org/ZelphirKaltstahl

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 3 - comparison with guile)
  2025-01-02  1:18     ` Zelphir Kaltstahl
@ 2025-01-02  7:44       ` Julien Lepiller
  2025-01-02 13:35         ` Zelphir Kaltstahl
  0 siblings, 1 reply; 10+ messages in thread
From: Julien Lepiller @ 2025-01-02  7:44 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: help-guix

I've seen ocamlfind being used by the build process of some packages. Then just a quick search on the internet. The readme of zarith also mentions it. It also mentions using ocamlc directly, but that didn't work for me.

Le 2 janvier 2025 02:18:25 GMT+01:00, Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> a écrit :
>On 31.12.24 15:57, Julien Lepiller wrote:
>> 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?
>
>Hi Julien!
>
>Thank you for figuring this out! It works for me as well.
>
>May I ask, how you found out about this?
>
>Best regards, Zelphir
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: OCaml package `ocaml-zarith` not working / Guix installed `ocamlc` not picking up installed libraries (addendum 3 - comparison with guile)
  2025-01-02  7:44       ` Julien Lepiller
@ 2025-01-02 13:35         ` Zelphir Kaltstahl
  0 siblings, 0 replies; 10+ messages in thread
From: Zelphir Kaltstahl @ 2025-01-02 13:35 UTC (permalink / raw)
  To: Julien Lepiller; +Cc: help-guix

Hello Julien!

Indeed, it is in the readme of zarith. I should have checked more thoroughly. I 
skipped that whole "Installation" section, because I thought: "I already 
installed it using Guix." ^^'

Anyway, now with library usage being possible and finally having a working 
factorial (haha), I can continue learning! Thanks you for your help!

Best wishes,
Zelphir

On 02.01.25 08:44, Julien Lepiller wrote:
> I've seen ocamlfind being used by the build process of some packages. Then just a quick search on the internet. The readme of zarith also mentions it. It also mentions using ocamlc directly, but that didn't work for me.
>
> Le 2 janvier 2025 02:18:25 GMT+01:00, Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> a écrit :
>> On 31.12.24 15:57, Julien Lepiller wrote:
>>> 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?
>> Hi Julien!
>>
>> Thank you for figuring this out! It works for me as well.
>>
>> May I ask, how you found out about this?
>>
>> Best regards, Zelphir
>>
-- 
repositories: https://notabug.org/ZelphirKaltstahl, https://codeberg.org/ZelphirKaltstahl



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-01-02 13:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2025-01-02  1:18     ` Zelphir Kaltstahl
2025-01-02  7:44       ` Julien Lepiller
2025-01-02 13:35         ` Zelphir Kaltstahl

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.