Nix build - linker command failed with exit code 1

So I’ve been trying to make my own nix package on my mac m1 for a Python project and thought it would be a good idea to start with something simple, GNU hello. I like to use flake so my flake.nix looks like this

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs = { self, nixpkgs }: let
    system = "aarch64-darwin";
    pkgs = import nixpkgs {inherit system;};
    in {
        packages.${system} = {
            hello = pkgs.stdenv.mkDerivation {
                pname = "hello";
                version = "2.12.1";
                src = pkgs.fetchurl {
                    url = "https://mirror.freedif.org/GNU/hello/hello-2.12.1.tar.gz";
                    sha256 = "sha256-jZkUKv2SV28wsM18tCqNxoCZmLxdYH2Idh9RLibH2yA=";
                };
                doCheck = true;
                doInstallCheck = true;
            };
            default = self.packages.${system}.hello;
            test = pkgs.hello;
        };

  };

but surprise, surprise! it doesn’t work and returned an error (running: nix build .#hello)

ld: symbol(s) not found for architecture arm64
clang-16: error: linker command failed with exit code 1 

so I looked up the real nixpkgs.hello source. and also tried to build from nixpkgs (running: nix build .#test) it worked fine and I couldn’t grasp why that worked and mine does not. Can someone help me out?

Cheers!

The essential part of the error is this:

       > Undefined symbols for architecture arm64:
       >   "_iconv", referenced from:
       >       _mem_cd_iconv in libhello.a(striconv.o)
       >       _str_cd_iconv in libhello.a(striconv.o)
       >      (maybe you meant: _str_cd_iconv, _xmem_cd_iconv , _xstr_iconv , _mem_cd_iconv , _str_iconv , _xstr_cd_iconv )
       >   "_iconv_close", referenced from:
       >       _str_iconv in libhello.a(striconv.o)
       >   "_iconv_open", referenced from:
       >       _str_iconv in libhello.a(striconv.o)
       > ld: symbol(s) not found for architecture arm64

So it’s an issue with linking iconv library.

You are looking at old hello definition for some reason. The current one has an essential patch which fixes this problem

1 Like

I followed the source from https://search.nixos.org/packages?query=hello on the 24.05 stable channel. They didn’t patch it then. added the lines to my code and now it builds perfectly fine. Thank you for pointing it out!