Cc lib linking issue

Hi,

I have an Raylib application that I developed on NixOS.
Now I want to get it working on my MacOS laptop too.

When building with cc, I get this error fatal error: 'Carbon/Carbon.h' file not found, which is included here: raylib/src/external/glfw/src/cocoa_platform.h.

This'Carbon/Carbon.h' is a file in the Cocoa framework and is packaged with the xcode install. When I compile raylib with /usr/bin/cc instead of the one in my nix store it works.

I’m really new to linking libs and I can’t find the needed documentation to proceed.
I’m either looking for a way to override the stdenv cc to /usr/bin/cc or a way to link the needed libs.

Thanks in advance!

Here is my flake.nix:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    naersk.url = "github:nix-community/naersk";
    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs = {
        nixpkgs.follows = "nixpkgs";
        flake-utils.follows = "flake-utils";
      };
    };
  };

  outputs = { self, nixpkgs, flake-utils, naersk, rust-overlay }:
    flake-utils.lib.eachDefaultSystem (system: let
      overlays = [ (import rust-overlay) ];
      # Read from `rust-toolchain.toml` instead of adding `rust-bin.nightly.latest.default` to devShell `buildInputs`
      rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;

      naerskLib = pkgs.callPackage naersk {
        cargo = rustToolchain;
        rustc = rustToolchain;
      };

      pkgs = import nixpkgs {
        inherit system overlays;
        config = {
          allowUnfree = true;
        };
      };


      # Libraries that are mostly needed for raylib to build
      libraries = with pkgs; [
        cmake
      ] ++ pkgs.lib.lists.optionals stdenv.isLinux [
        clang
        libclang
        libcxx # C++ std library
        libGL

        xorg.libX11
        xorg.libXrandr
        xorg.libXinerama
        xorg.libXcursor
        xorg.libXi
        xorg.libXi
        libatomic_ops
        mesa
        alsa-lib


        glibc

        # [Wayland]
        wayland
        wayland-protocols
        libxkbcommon
      ] ++ pkgs.lib.lists.optionals stdenv.isDarwin [
        # darwin.xcode # This is monstrously huge, often fails to build and is installed anyway
      ];

      packages = with pkgs; [
      ];

      # Inputs needed at compile-time
      nativeBuildInputs = with pkgs; [ rustToolchain ];
      # Inputs needed at runtime
      buildInputs = with pkgs; [ ] ++ packages ++ libraries;
    in
    {
      packages.default = naerskLib.buildPackage {
         src = ./.;
      };

      devShells = {
        default = pkgs.mkShell {
          inherit buildInputs;
          nativeBuildInputs = nativeBuildInputs ++ [
            pkgs.cargo-watch
          ];

          # shellHook = ''
          # export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath libraries}
          # '';
        };
      };
    });
}

There is darwin.CarbonHeaders, which should likely suffice instead of pulling in darwin.xcode.

This is probably a dumb question but:
I added darwin.CarbonHeaders to both buildInputs and nativeBuildInputs and I’m still getting the same error.

Is there something else I should do?

Maybe you also need darwin.apple_sdk.frameworks.Cocoa? In any case, it only needs to go into buildInputs, not into nativeBuildInputs.

1 Like

Thanks that works!

I couldn’t find this via search.nixos.org. Is this by design?
Is there some place I could easily search for darwin.apple_sdk.* (other than the nixpkgs repo)?

Again, thanks a lot!

1 Like

I have no idea why apple_sdk does not show up on search.nixos.org, unfortunately.

1 Like