How to link static executable with libc++

Viewed 511

I'm investigating nix as a build tool for my project. Currently I'm struggling with building and linking static executable using llvm toolchain and libc++.

let
    pkgs = import <nixpkgs> {};
    stdenv = pkgs.llvmPackages_10.libcxxStdenv;
in

stdenv.mkDerivation {
  name = "my-app";
  src = ./.;

 buildInputs = [
    glibc.static
  ];

buildPhase = "c++ -o main main.cpp -static";

  installPhase = ''
    mkdir -p $out/bin
    cp main $out/bin/
  '';
}

**Is there way to make it build, for example by adding similar dependency like glibc.static, but for libcxx?

Error with glibc.static on list

these derivations will be built:
  /nix/store/l2l8bjcxmy218cyc22fvmha84f7fyhbk-my-app.drv
building '/nix/store/l2l8bjcxmy218cyc22fvmha84f7fyhbk-my-app.drv'...
unpacking sources
unpacking source archive /nix/store/5bggb5pmzciw6763dq0qrgzp6lgs8cx8-drone
source root is drone
patching sources
configuring
no configure script, doing nothing
building
/nix/store/gmi6xrkl95h6iypv00dvdpm3f4md9i6i-binutils-2.31.1/bin/ld: /nix/store/fy8nmvrkb4bzfmca136crwlz69fzzbqn-libc++-10.0.1/lib/libc++.a(ios.cpp.o): in function `std::__1::iostream_category()':
(.text+0x114): undefined reference to `__cxa_guard_acquire'
/nix/store/gmi6xrkl95h6iypv00dvdpm3f4md9i6i-binutils-2.31.1/bin/ld: (.text+0x152): undefined reference to `__cxa_guard_release'
/nix/store/gmi6xrkl95h6iypv00dvdpm3f4md9i6i-binutils-2.31.1/bin/ld: /nix/store/fy8nmvrkb4bzfmca136crwlz69fzzbqn-libc++-10.0.1/lib/libc++.a(ios.cpp.o):(.data.rel.ro._ZTVNSt3__18ios_base7failureE[_ZTVNSt3__18ios_base7failureE]+0x20): undefined reference to `std::runtime_error::what() const'
/nix/store/gmi6xrkl95h6iypv00dvdpm3f4md9i6i-binutils-2.31.1/bin/ld: /nix/store/fy8nmvrkb4bzfmca136crwlz69fzzbqn-libc++-10.0.1/lib/libc++.a(iostream.cpp.o): in function `std::__1::ios_base::Init::Init()':
(.text+0x6f9): undefined reference to `__cxa_guard_acquire'
/nix/store/gmi6xrkl95h6iypv00dvdpm3f4md9i6i-binutils-2.31.1/bin/ld: (.text+0x71c): undefined reference to `__cxa_guard_release'
/nix/store/gmi6xrkl95h6iypv00dvdpm3f4md9i6i-binutils-2.31.1/bin/ld: /nix/store/fy8nmvrkb4bzfmca136crwlz69fzzbqn-libc++-10.0.1/lib/libc++.a(iostream.cpp.o): in function `std::__1::ios_base::Init::Init() [clone .cold]':
(.text.unlikely+0x148): undefined reference to `__cxa_guard_abort'
/nix/store/gmi6xrkl95h6iypv00dvdpm3f4md9i6i-binutils-2.31.1/bin/ld: /nix/store/fy8nmvrkb4bzfmca136crwlz69fzzbqn-libc++-10.0.1/lib/libc++.a(locale.cpp.o): in function `std::__1::__time_get_c_storage<char>::__weeks() const':
(.text+0x43a1): undefined reference to `__cxa_guard_acquire'
...
(.text+0x1f4): undefined reference to `pthread_mutex_unlock'
/nix/store/gmi6xrkl95h6iypv00dvdpm3f4md9i6i-binutils-2.31.1/bin/ld: /nix/store/fy8nmvrkb4bzfmca136crwlz69fzzbqn-libc++-10.0.1/lib/libc++.a(condition_variable_destructor.cpp.o): in function `std::__1::condition_variable::~condition_variable()':
(.text+0x1): undefined reference to `pthread_cond_destroy'
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
builder for '/nix/store/l2l8bjcxmy218cyc22fvmha84f7fyhbk-my-app.drv' failed with exit code 1
error: build of '/nix/store/l2l8bjcxmy218cyc22fvmha84f7fyhbk-my-app.drv' failed

otherwise it is just about linker can not find libc

0 Answers
Related