C++ flake -stdlib=libstdc++

Hi.
Almost get the perfect NixOS config: The thing is I get this error:
The thing is, I copied this flake and try to use it:
Could you help me, almost get it.

vim flake.nix

{
  description = "C/C++ environment";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, utils, ... }@inputs:
    utils.lib.eachDefaultSystem (
      system:
      let
        p = import nixpkgs { 
				inherit system;
				config = { 
					allowUnfree = true; 
				}; 
			};
        llvm = p.llvmPackages_latest;

        # simple script which replaces the functionality of make
        # it works with <math.h> and includes debugging symbols by default
        # it will be updated as per needs

        # arguments: outfile
        # basic usage example: mk main [flags]
        mymake = p.writeShellScriptBin "mk" ''
          if [ -f "$1.c" ]; then
            i="$1.c"
            c=$CC
          else
            i="$1.cpp"
            c=$CXX
          fi
          o=$1
          shift
          $c -ggdb $i -o $o -lm -Wall $@
        '';
      in
      {
        devShell = p.mkShell.override { stdenv = p.clangStdenv; } rec {
          packages = with p; [
			# builder
			gnumake
			cmake
			cmake-format
			cmake-language-server
			gcc
			gcc_multi
			gcc13
			extra-cmake-modules
			ninja
			bear
			pkg-config

			# debugger
			llvm.lldb
			gdb

			# fix headers not found
			clang-tools

			# LSP and compiler
			llvm.libstdcxxClang

			# other tools
			cppcheck
			llvm.libllvm
			valgrind
			mymake
			conan

			# stdlib for cpp
			llvm.libcxx
				
			# libs
			libGL
			libGLU
			libglvnd
			libvdpau-va-gl
			faac
			faad2
			freeglut
			glew
			glfw
			glm
			mesa.dev

			SDL2
			SDL2_ttf
			SDL2_net
			SDL2_gfx
			SDL2_sound
			SDL2_mixer
			SDL2_image

			vulkan-tools
			vulkan-loader
			vulkan-headers
			vulkan-tools-lunarg
          ];
          name = "C";
        };
      }
    );
}

nix develop

CMake Error at /nix/store/1rkcif5bqs89a9s9ksjb9gqs5wm99h2w-cmake-3.25.3/share/cmake-3.25/Modules/CMakeTestCXXCompiler.cmake:63 (message):
  The C++ compiler

    "/nix/store/lfmzkylwgng6rwpj79wv5wcr79idp8pf-gcc-wrapper-13.1.0/bin/g++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/cris/Workspace/C++/SDL_Game_00/build/Debug/CMakeFiles/CMakeScratch/TryCompile-GReXAA
    
    Run Build Command(s):/nix/store/62p3w9xmjkymc0pd55l076a92hd0splg-gnumake-4.4.1/bin/make -f Makefile cmTC_80819/fast && /nix/store/62p3w9xmjkymc0pd55l076a92hd0splg-gnumake-4.4.1/bin/make  -f CMakeFiles/cmTC_80819.dir/build.make CMakeFiles/cmTC_80819.dir/build
    make[1]: Entering directory '/home/cris/Workspace/C++/SDL_Game_00/build/Debug/CMakeFiles/CMakeScratch/TryCompile-GReXAA'
    Building CXX object CMakeFiles/cmTC_80819.dir/testCXXCompiler.cxx.o
    /nix/store/lfmzkylwgng6rwpj79wv5wcr79idp8pf-gcc-wrapper-13.1.0/bin/g++   -m64 -stdlib=libstdc++  -std=gnu++17 -o CMakeFiles/cmTC_80819.dir/testCXXCompiler.cxx.o -c /home/cris/Workspace/C++/SDL_Game_00/build/Debug/CMakeFiles/CMakeScratch/TryCompile-GReXAA/testCXXCompiler.cxx
    g++: error: unrecognized command-line option ‘-stdlib=libstdc++’
    make[1]: *** [CMakeFiles/cmTC_80819.dir/build.make:78: CMakeFiles/cmTC_80819.dir/testCXXCompiler.cxx.o] Error 1
    make[1]: Leaving directory '/home/cris/Workspace/C++/SDL_Game_00/build/Debug/CMakeFiles/CMakeScratch/TryCompile-GReXAA'
    make: *** [Makefile:127: cmTC_80819/fast] Error 2
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:24 (project)

Putting several different compilers into a single dev-env feels like recipe for trouble.

In this case… you chose a clang stdenv. OK… but your build scripts are trying to use g++ (from gcc). It’s best to use stdenv overridden with the exact compiler you want to use.

Ohh my bad.

devShell = p.mkShell.override { stdenv = p.clangStdenv; } ## <-- As I understand, this is for Clang
devShell = p.mkShell.override { stdenv = p.gcc13Stdenv; } ## And this for Gcc

The thing is. I already made it, but:
No matter if I use p.gcc13Stdenv, if I add to the packages llvm.libstdcxxClang, it will use clang.

In this case, Nix will try to use X or Y if there is a lib ?

I think libstdcxxClang is a clang with libstdc++ library (not the llvm std library libc++).
I think the whole C++ build system is really messy, and package names are very arakane and hardly any documentation exists which describes the certain package. Does anybody know what the difference is between pkgs.llvmPackages_X.clang and pkgs.clangStdenv?

1 Like