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

-Lsrc/libutil is too late in linker path, fails with a link error: download.cc:905: undefined reference to `nix::runProgram #3087

Closed
trofi opened this issue Sep 6, 2019 · 3 comments · Fixed by #5187 or #6060
Labels

Comments

@trofi
Copy link
Contributor

trofi commented Sep 6, 2019

The bug happens when I try to build nix-2.3 on a system with nix-2.2.2 installed in system (with /usr/lib64/libnixstore.so).

Linker pulls in system /usr/lib64/libnixstore.so and fails as:

nix-2.3 $ LANG=C make V=1
x86_64-pc-linux-gnu-g++ -std=c++17 -o /tmp/portage/sys-apps/nix-2.3/work/nix-2.3/src/libstore/libnixstore.so -shared -L/usr/lib64 -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,--no-copy-dt-needed-entries src/libstore/binary-cache-store.o src/libstore/build.o src/libstore/builtins/buildenv.o src/libstore/builtins/fetchurl.o src/libstore/crypto.o src/libstore/derivations.o src/libstore/download.o src/libstore/export-import.o src/libstore/gc.o src/libstore/globals.o src/libstore/http-binary-cache-store.o src/libstore/legacy-ssh-store.o src/libstore/local-binary-cache-store.o src/libstore/local-fs-store.o src/libstore/local-store.o src/libstore/machines.o src/libstore/misc.o src/libstore/nar-accessor.o src/libstore/nar-info-disk-cache.o src/libstore/nar-info.o src/libstore/optimise-store.o src/libstore/parsed-derivations.o src/libstore/pathlocks.o src/libstore/profiles.o src/libstore/references.o src/libstore/remote-fs-accessor.o src/libstore/remote-store.o src/libstore/s3-binary-cache-store.o src/libstore/sqlite.o src/libstore/ssh-store.o src/libstore/ssh.o src/libstore/store-api.o -lsqlite3 -lbz2 -lcurl -lsodium -pthread -ldl -lseccomp -Wl,-z,defs -Wl,-soname=libnixstore.so    -Wl,-rpath,/tmp/portage/sys-apps/nix-2.3/work/nix-2.3/src/libutil -Lsrc/libutil -lnixutil
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/libstore/build.o: in function `bool std::operator==<char, std::char_traits<char>, std::allocator<char> >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)':
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9/bits/basic_string.h:6177: undefined reference to `nix::nativeSystem[abi:cxx11]'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9/bits/basic_string.h:6177: undefined reference to `nix::nativeSystem[abi:cxx11]'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9/bits/basic_string.h:6177: undefined reference to `nix::nativeSystem[abi:cxx11]'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/libstore/build.o: in function `nix::DerivationGoal::startBuilder()':
/tmp/portage/sys-apps/nix-2.3/work/nix-2.3/src/libstore/build.cc:2212: undefined reference to `nix::runProgram(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, std::__cxx11::list<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::optional<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/../../../../x86_64-pc-linux-gnu/bin/ld: src/libstore/download.o: in function `nix::Downloader::downloadCached(nix::ref<nix::Store>, nix::CachedDownloadRequest const&)':
/tmp/portage/sys-apps/nix-2.3/work/nix-2.3/src/libstore/download.cc:905: undefined reference to `nix::runProgram(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, std::__cxx11::list<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::optional<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > const&)'
collect2: error: ld returned 1 exit status
make: *** [mk/lib.mk:104: src/libstore/libnixstore.so] Error 1

Note, the problem here is -L parameter ordering:
x86_64-pc-linux-gnu-g++ -std=c++17 -o .../libnixstore.so -shared -L/usr/lib64 ... -Lsrc/libutil -lnixutil. libnixstore.so is pulled from /usr/lib64.

Ideally linker flags should mention local paths first and then external ones.

@trofi
Copy link
Contributor Author

trofi commented Sep 7, 2019

singron added a commit to singron/nix that referenced this issue Oct 17, 2019
Otherwise previous -L flags could cause the linker to use globally
installed versions of libraries instead of the ones that were just
compiled.

Fix NixOS#3087
@singron
Copy link
Contributor

singron commented Oct 22, 2019

Do you accept pull requests? Is there anyone I can assign as reviewer to #3154? The Arch Linux User Repository (https://aur.archlinux.org/packages/nix) linked to my commit, and I'm mildly worried about unintentionally hosting unmerged changes for them.

singron added a commit to singron/nix that referenced this issue Nov 8, 2019
Otherwise previous -L flags could cause the linker to use globally
installed versions of libraries instead of the ones that were just
compiled.

Fix NixOS#3087
@stale
Copy link

stale bot commented Feb 18, 2021

I marked this as stale due to inactivity. → More info

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