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

bug: rustc missing library iconv on darwin #3482

Closed
neosimsim opened this issue Dec 8, 2022 · 9 comments
Closed

bug: rustc missing library iconv on darwin #3482

neosimsim opened this issue Dec 8, 2022 · 9 comments
Assignees
Labels
bug triage Issues or feature request that have not been triaged yet

Comments

@neosimsim
Copy link
Contributor

neosimsim commented Dec 8, 2022

Issue description

I installed rust and cargo using the following flake.nix

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    home-manager.url = "github:nix-community/home-manager";
  };

  outputs = { self, nixpkgs, home-manager }: {

    homeConfigurations."neosimsim" = home-manager.lib.homeManagerConfiguration {

      pkgs = nixpkgs.legacyPackages.aarch64-darwin;

      modules = [
        ({ config, pkgs, ... }: {
          nix = {
            package = pkgs.nix;
            settings.experimental-features = [
              "nix-command"
              "flakes"
            ];
          };

          programs.home-manager.enable = true;

          home = {
            stateVersion = "22.05";
            username = "neosimsim";
            homeDirectory = "/Users/neosimsim";
            packages = with pkgs; [
              git
              fish
              rustc
              cargo
              clang
            ];
          };
        })
      ];
    };

  };
}

But when I try compile the following main.rs

fn main() {
    // Statements here are executed when the compiled binary is called

    // Print text to the console
    println!("Hello World!");
}

The build failed with

$ rustc main.rs
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-arch" "arm64" "/var/folders/tc/tmq0yq29117br__lmw5_3c7c0000gp/T/rustcsU4rQM/symbols.o" "main.main.dd7fc0f6-cgu.0.rcgu.o" "main.main.dd7fc0f6-cgu.1.rcgu.o" "main.main.dd7fc0f6-cgu.2.rcgu.o" "main.main.dd7fc0f6-cgu.3.rcgu.o" "main.main.dd7fc0f6-cgu.4.rcgu.o" "main.main.dd7fc0f6-cgu.5.rcgu.o" "main.main.dd7fc0f6-cgu.6.rcgu.o" "main.main.dd7fc0f6-cgu.7.rcgu.o" "main.s32jh9uv6aqhr3e.rcgu.o" "-L" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libstd-08068d401c25d211.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libpanic_unwind-84be07e68b9d00f4.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libobject-4804c562fc61a807.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libmemchr-279301e6a5d99fea.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libaddr2line-fbfb344f09805b90.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libgimli-616191dd1d974165.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/librustc_demangle-4687ef078813d96d.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libstd_detect-1386b7e41dd1fd86.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libhashbrown-26b1aa4af9d5f07a.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libminiz_oxide-8a7d5d906c81e365.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libadler-327750ded6594992.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_alloc-b801be618a24f1bf.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libunwind-fa75ed5f72174942.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libcfg_if-adf0011e71898575.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/liblibc-3d5bcaabca1cfe44.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/liballoc-cd287cf1e41c0ec4.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/librustc_std_workspace_core-d99e291378cbf0b8.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libcore-fcdbad0d5b23b740.rlib" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib/libcompiler_builtins-9ba449e7b506e8b4.rlib" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv" "-L" "/nix/store/y1zgd02zpwwd71i41riyyq7rs6l20sqs-rustc-1.64.0/lib/rustlib/aarch64-apple-darwin/lib" "-o" "main" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: ld: library not found for -liconv
          clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: aborting due to previous error

I could fix my setup by adding

home.sessionVariables.LIBRARY_PATH = ''${lib.makeLibraryPath [pkgs.libiconv]}''${LIBRARY_PATH:+:$LIBRARY_PATH}'';
programs.fish.enable = true;

But I have the impression this should not be necessary.

Maintainer CC

No response

System information

- system: `"aarch64-darwin"`
 - host os: `Darwin 21.5.0, macOS 12.4`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.9.0`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
@neosimsim neosimsim added bug triage Issues or feature request that have not been triaged yet labels Dec 8, 2022
@luxus
Copy link

luxus commented Dec 20, 2022

@neosimsim any updates on this? did you found a better solution?

@neosimsim
Copy link
Contributor Author

@neosimsim any updates on this? did you found a better solution?

Not yet, no.

@LucianDavies
Copy link

I have this same problem also..

@ncfavier
Copy link
Member

This is unrelated to Home Manager and a duplicate of NixOS/nixpkgs#206242.

@ncfavier ncfavier closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2023
@ncfavier
Copy link
Member

Note that rust 1.66 (which apparently fixes the issue out of the box) is in nixpkgs unstable already, so you might want to use rustc from unstable.

@neosimsim
Copy link
Contributor Author

neosimsim commented Feb 23, 2023

Yes it works. Thanks for the hint.

ldeck added a commit to ldeck/nix-home that referenced this issue Sep 8, 2023
See nix-community/home-manager#3482

note: ld: library not found for -liconv
          clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
@rupurt
Copy link

rupurt commented Jan 24, 2024

@ncfavier I'm still running into this problem with rustc 1.75.0 (82e1608df 2023-12-21) (built from a source tarball) which is installed as a nix package

blitz added a commit to blitz/gitlab-timelogs that referenced this issue Jul 31, 2024
The MacOS build fails with:

> ++ command cargo build --release --message-format json-render-diagnostics --locked
>    Compiling gitlab-timelogs v0.2.2 (/private/tmp/nix-build-gitlab-timelogs-0.2.2.drv-0/8bm81sjfqmsk7lclw7pnddrxv785aaj3-source)
> error: linking with `cc` failed: exit status: 1

Fix by manually adding iconv as a dependency.

Other people also have encountered this:
nix-community/home-manager#3482
phip1611 pushed a commit to blitz/gitlab-timelogs that referenced this issue Aug 13, 2024
The MacOS build fails with:

> ++ command cargo build --release --message-format json-render-diagnostics --locked
>    Compiling gitlab-timelogs v0.2.2 (/private/tmp/nix-build-gitlab-timelogs-0.2.2.drv-0/8bm81sjfqmsk7lclw7pnddrxv785aaj3-source)
> error: linking with `cc` failed: exit status: 1

Fix by manually adding iconv as a dependency.

Other people also have encountered this:
nix-community/home-manager#3482
@theoparis
Copy link

Same issue here, I ended up following the fix referenced in the commit above which involves conditionally adding libiconv to buildInputs.

@alyssais
Copy link
Member

Generally libiconv should be depended on unconditionally, as it's not part of libc on more platforms than just Darwin, and it's a no-op on platforms where it is part of libc (most Linux ones).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triage Issues or feature request that have not been triaged yet
Projects
None yet
Development

No branches or pull requests

10 participants