Nixpkgs: Idris won't find libgmp when linking compiled binaries

Created on 18 Oct 2015  Â·  26Comments  Â·  Source: NixOS/nixpkgs

Let's try to compile something simple as in example —
https://eb.host.cs.st-andrews.ac.uk/Idris/first.html
(containing main : IO (); main = putStrLn "Hello world";)

# idris hello.idr -o hello
gcc: rawSystem: runInteractiveProcess: exec: does not exist (No such file or directory)

Okay, let's install gcc —
# idris hello.idr -o hello
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
FAILURE: "gcc" ["-O2","-fwrapv","-fno-strict-overflow","-DHAS_PTHREAD","-DIDRIS_ENABLE_STATS","-I.","-x","c","/tmp/idris7198853861649760492","-L/nix/store/3x07l4v8wv8msri8r7w5lhb8hg4vw734-idris-0.9.19.1/share/x86_64-linux-ghc-7.10.2/idris-0.9.19.1/rts","-lidris_rts","-lgmp","-lpthread","-I/nix/store/3x07l4v8wv8msri8r7w5lhb8hg4vw734-idris-0.9.19.1/share/x86_64-linux-ghc-7.10.2/idris-0.9.19.1/rts","-lm","-I.","-I.","-I/nix/store/3x07l4v8wv8msri8r7w5lhb8hg4vw734-idris-0.9.19.1/share/x86_64-linux-ghc-7.10.2/idris-0.9.19.1/prelude","-I/nix/store/3x07l4v8wv8msri8r7w5lhb8hg4vw734-idris-0.9.19.1/share/x86_64-linux-ghc-7.10.2/idris-0.9.19.1/base","-o","hello"]

Now installed gmp, but it doesn't matter —
# idris hello.idr -o hello
/nix/store/kxf1p7l7lgm6j5mjzkiwcwzc98s9f1az-binutils-2.23.1/bin/ld: cannot find -lgmp
[...the same as in previous command...]

What can i do to compile (at least) hello.idr?

Idris REPL is almost ok except some things related to the "outer world", such as putStrLn.
emacs interface is ok.

bug

All 26 comments

Idris did have gcc and libgmp available at the time it was built, but apparently it didn't record the paths necessary to reach those tools. :disappointed:. Maybe this can be fixed by patching the source code. The alternative is to wrap the Idris binary with a script that sets up the proper environment.

The alternative is to wrap the Idris binary
with a script that sets up the proper environment.

Ok. It's not such a scary thing.
I tried to export PATH = $PATH:/nix/store/[...]-gmp-5.1.3/lib and include
Nothing changed...
What PATH's i need to set?

There used to be a wrapper which set NIX_CFLAGS_COMPILE. It looked a bit like this:

https://github.com/idris-hackers/idrispkgs/blob/master/idris_plain/wrapper.nix#L9

I tried to export all paths that i found in your link...
The same thing ;-(
% idris ./hello.idr -o hello
/nix/store/v7h3j43vx0dz5ahhkxg5z50by2iqc6k1-binutils-2.23.1/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
FAILURE: "gcc" ["-O2","-fwrapv","-fno-strict-overflow","-DHAS_PTHREAD","-DIDRIS_ENABLE_STATS","-I.","-x","c","/tmp/idris20448977631967513926","-L/nix/store/j9kvp0rbg4hs4xjilg2ppl613pmx69q3-idris-0.9.19.1/share/x86_64-linux-ghc-7.10.2/idris-0.9.19.1/rts","-lidris_rts","-lgmp","-lpthread","-I/nix/store/j9kvp0rbg4hs4xjilg2ppl613pmx69q3-idris-0.9.19.1/share/x86_64-linux-ghc-7.10.2/idris-0.9.19.1/rts","-lm","-I.","-I.","-I/nix/store/j9kvp0rbg4hs4xjilg2ppl613pmx69q3-idris-0.9.19.1/share/x86_64-linux-ghc-7.10.2/idris-0.9.19.1/prelude","-I/nix/store/j9kvp0rbg4hs4xjilg2ppl613pmx69q3-idris-0.9.19.1/share/x86_64-linux-ghc-7.10.2/idris-0.9.19.1/base","-o","hello"]

Libraries aren't searched on $PATH. Using nix-shell with -p gmp -p gcc -p idris (and perhaps other needed things) is probably the easiest work around to get the environment set up.

Yes!
nix-shell -p gmp -p gcc (no -p idris)
Big thanks! It works for me! ;-)

As far as I know these issues should be fixed in Idris version 0.9.20.

Idris won't find libgmp when linking compiled binaries

Idris also won't find a gcc if i do not install it explicitly.
As i can guess, it's a dependency issue?

As far as I know these issues should be fixed in Idris version 0.9.20

Is it worth to close this issue now or wait for 0.9.20?

Idris also won't find a gcc if i do not install it explicitly.

That seems okay to me. Idris doesn't want to hard-code the path of the compiler so that any C compiler can be used, which is reasonable.

Is it worth to close this issue now or wait for 0.9.20?

0.9.20 is already in Nixpkgs master. It just hasn't hit the unstable channel yet. Personally, I'm fine with leaving the issue open until we've confirmed that the new version really improves matters.

Idris doesn't want to hard-code the path of the compiler
so that any C compiler can be used, which is reasonable.

Reasonably.

Personally, I'm fine with leaving the issue open

Ok, let's wait for 0.9.20 in unstable.

% idris -V
[...]Version 0.9.20[...]

Problem remains the same (gmp installed) —
% idris hello.idr -o hello
/nix/store/v7h3j43vx0dz5ahhkxg5z50by2iqc6k1-binutils-2.23.1/bin/ld: cannot find -lgmp
[...]

@shlevy, do you know why Idris still won't find libgmp? I thought that your upstream PR fixed that?

idris-lang/Idris-dev#2739 fixed finding gmp at _Idris_ compile time. As a temporary workaround NIX_LDFLAGS pointing to your lib dir might work.

Do you think it's a good idea to open a PR to pass -L/path/to/compiletime/gmp in Idris's C backend? I'm not sure the same thoughts on having gcc not hard-coded don't apply

Do you think it's a good idea to open a PR to pass -L/path/to/compiletime/gmp in Idris's C backend?

Yes, I believe Idris should do that.

I'm not sure the same thoughts on having gcc not hard-coded don't apply

IMHO, it's okay to expect users to configure their $PATH so that additional programs (like gcc) can be found, but expecting users to configure $LIBRARY_PATH etc. to make Idris run is too much. Idris should work out of the box, really, and then it should offer command-line flags that allow users to override the defaults if necessary.

@edwinb Any thoughts on the above?

@peti For what it's worth, I think it makes more sense for the env setup script that comes with nix (for nix-env-installed packages) and NixOS (for nixos-installed packages) should set up the library path by default, much like they set up $PATH. After all, everywhere but in nix installing gmp will work with Idris.

Well, I don't know much about Idris and I won't be able to contribute fixes for these issues either way. I'll leave those decisions in the capable hands of those who are actually doing the work.

That seems okay to me. Idris doesn't want to hard-code the path of the compiler so that any C compiler can be used, which is reasonable.

Reflecting on this, I think the proper way to do this in nixpkgs would
be to rename idris to idris-no-deps, and make

idris = wrapAThing idris-no-deps {
   path = [ gcc ];
   lib  = [ libgmp ];
};

This way everyone gets happy: those who want

environment.systemPackages = [ idris ];

to just work, and those who want to customize it.

(triage) solved?

@Profpatsch No, not solved currently. But we need feedback from the Idris folks (@edwinb ?) on whether it's desired to have the compile time path to gmp passed from Idris itself or if we should wrap it ourselves.

I just ran into this very same issue when trying Idris - how can we proceed here? Is there some sort of quickfix that I could apply?

» idris Hello.idr -o hello                                                                            130 ↵ 
/nix/store/9kxhc2f3j5lcyh00zcrifvfly33n5m4r-binutils-2.27/bin/ld: cannot find -lgmp                                                            
collect2: error: ld returned 1 exit status                                                                                                     
FAILURE: "gcc" ["-O2","-fwrapv","-fno-strict-overflow","-DHAS_PTHREAD","-DIDRIS_ENABLE_STATS","-I.","/tmp/idris1957747793424238335.c","-L/nix/s
tore/56rjpjhbiasr7ad47n8sy8ldp2gck79c-idris-1.0/share/x86_64-linux-ghc-8.0.2/idris-1.0/rts/","-lidris_rts","-lgmp","-lpthread","-I/nix/store/56
rjpjhbiasr7ad47n8sy8ldp2gck79c-idris-1.0/share/x86_64-linux-ghc-8.0.2/idris-1.0/rts/","-lm","-I.","-I.","-I/nix/store/56rjpjhbiasr7ad47n8sy8ldp
2gck79c-idris-1.0/share/x86_64-linux-ghc-8.0.2/idris-1.0/libs/prelude","-I/nix/store/56rjpjhbiasr7ad47n8sy8ldp2gck79c-idris-1.0/share/x86_64-li
nux-ghc-8.0.2/idris-1.0/libs/base","-o","hello"]                 

Given that Edwin Brady is probably not going to respond, and that Idris version 1 is already out without a fix to these problems, shall we just wrap gcc and libgmp?

IMHO, the best way would be as oxij proposed —
to make "idris" and "idris-no-deps" packages.

any movement on this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

copumpkin picture copumpkin  Â·  3Comments

ghost picture ghost  Â·  3Comments

tomberek picture tomberek  Â·  3Comments

copumpkin picture copumpkin  Â·  3Comments

sid-kap picture sid-kap  Â·  3Comments