Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove -L/ and -l: from linker flags #4719

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

spitulax
Copy link

This is the actual fix to NixOS/nixpkgs#338972 and many other issues with linking on Nix build system. The issue may have been caused by using -l: to specify the path to libraries and -L/ to set the linker search path. The linker could not find the libraries only when building using Nix stdenv. Building inside a nix shell does not trigger this issue. Probably it has something to do with build sandboxing, but I'm not too knowledgeable on this matter.

I found the solution when I was trying to isolate the issue using a simple C program and a static library. Building this with nix stdenv, resulting in the linker not being able to found the library.

buildPhase = ''
    gcc -o main main.c -L/ -l:$(pwd)/lib/libh.a
'';
/nix/store/j7p46r8v9gcpbxx89pbqlh61zhd33gzv-binutils-2.43.1/bin/ld: cannot find -l:/build/source/lib/libh.a: No such file or directory

But removing -L/ and -l: does the trick.

buildPhase = ''
    gcc -o main main.c $(pwd)/lib/libh.a
'';

I also tested this patch on Debian and it seemed to work fine.

@gingerBill
Copy link
Member

Wouldn't it better to disable them just for Nix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants