[Nix-dev] C compiler cannot create executables

Eelco Dolstra eelco at cs.uu.nl
Wed Jan 12 13:43:12 CET 2005


Hi,

On 7-jan-05, at 23:23, Eelco Visser wrote:

> Ok, I figured it out, at least for the current setting I *should* not
> use the /usr/lib paths, thus only use paths in the /nix/store to link
> against:
>
> export NIX_CFLAGS_COMPILE=" -I/home/visser/.nix-profile/include "
> export NIX_CFLAGS_LINK=" -L/home/visser/.nix-profile/lib  "
> export NIX_LDFLAGS=" -L/home/visser/.nix-profile/lib  "

Exactly.  Using things from /lib or /usr/lib is not really supported by 
the GCC in Nixpkgs.  It will mess up Glibc and possibly GCC's own 
libraries (libstdc++, libgcc).  In any case, passing -L/usr/lib is not 
enough for shared libraries; you also have to add them to the rpath: 
-Wl,-rpath,/usr/lib.  Plus possibly -Wl,-rpath,/lib for libraries in 
/usr/lib that set a SONAME to point to a library in /lib.

For instance,

$ export NIX_LDFLAGS="-L/usr/lib -rpath,/lib"
$ gcc -I/usr/include foo.c -lreadline -lncurses

However, the resulting binary will link against /lib/libc.so, which may 
or may not work depending on what other libraries you link against.

I think there is a fix for this on Armijn's nixpkgs branch.

-- 
Eelco Dolstra | http://www.cs.uu.nl/~eelco




More information about the nix-dev mailing list