Hello! I’m new to all this. I have a very simple toy SDL2 app I’m making to learn how to use nix. I’m on NixOS. The project is a flake that uses CMake; I must be doing something abnormal, because when I try to run nix develop && cmake ., cmake fails with this error, which I haven’t been able to find online:
-- The C compiler identification is GNU 9.5.0
-- The CXX compiler identification is GNU 9.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /nix/store/qa00jx7v8r3z6kaqhc8kg3bybk801pwp-gcc-wrapper-9.5.0/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /nix/store/qa00jx7v8r3z6kaqhc8kg3bybk801pwp-gcc-wrapper-9.5.0/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:6 (find_package):
Found package configuration file:
/nix/store/pl6vn3iqs7icf2czwblf1kmkyqr5xx0i-SDL2-2.28.5-dev/lib/cmake/SDL2/sdl2-config.cmake
but it set SDL2_FOUND to FALSE so package "SDL2" is considered to be NOT
FOUND.
What is happening, and what should I do?
Here is my flake.nix:
{
description = "A simple SDL app, written in C";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
# This is the list of architectures that work with this project
systems = [
"x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"
];
perSystem = { config, self', inputs', pkgs, system, ... }: {
# devShells.default describes the default shell with C++, cmake, boost,
# and catch2
devShells.default = pkgs.mkShell {
packages = with pkgs; [
# C++ Compiler is already part of stdenv
cmake
gcc9
SDL2
SDL2.dev
];
};
};
};
}
Here is my CMakeLists.txt (more or less a carbon copy of the template given by the SDL wiki):
However, the SDL2_LIBDIR folder does not contain the file libSDL2main.a, but the file libSDL2main.la (see /nix/store/21ps3g6b908wxj8q6ghh1drjm4idsw4z-SDL2-2.30.2/lib/libSDL2main.la).
If that is the case, the solution would be suggesting a package fix. Maybe a more experienced user could help out.
A potential workaround could be using the SDL source as a input.
CMake Error at CMakeLists.txt:7 (find_package):
Found package configuration file:
/nix/store/arszgqa52qjp3bqpnqkbhnvlzacl5wlv-SDL2-2.30.4-dev/lib/cmake/SDL2/sdl2-config.cmake
but it set SDL2_FOUND to FALSE so package "SDL2" is considered to be NOT
FOUND.
-- Configuring incomplete, errors occurred!
make: *** [Makefile:233: cmake_check_build_system] Error 1
I understand that the root cause of the issue lies within the package itself. If that is the case, I would be confident that this will be resolved in future versions. In the meantime, as a workaround, you may add the following to your CMakeLists.txt file, it has worked on my end: