NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.82k stars 13.92k forks source link

SDL2_ttf failing to compile C #296692

Closed Ciflire closed 7 months ago

Ciflire commented 7 months ago

Describe the bug

Failing to compile C using SDL2_ttf because of relative path in include

Steps To Reproduce

Steps to reproduce the behavior:

  1. Create a project using SDL2_ttf
  2. try to compile
  3. get the following error
    /nix/store/n7abd7wf1wavllgyrnifv45xknadd3ps-SDL2_ttf-2.20.2/include/SDL2/SDL_ttf.h:39:10: fatal error: SDL.h: No such file or directory
    39 | #include "SDL.h"
      |          ^~~~~~~
    compilation terminated.
    make: *** [makefile:23: ta] Error 1

Expected behavior

That it compiles ?

Notify maintainers

@sternenseemann @reckenrode

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

    nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.8.0, NixOS, 24.05 (Uakari), 24.05.20240314.d691274`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"nixos, nixpkgs"`
 - channels(ciflire): `""`
 - nixpkgs: `/nix/store/9mf8fkjw3vw1gm4s6j5fqlwrv5wf2knf-source`

Add a :+1: reaction to issues you find important.

sternenseemann commented 7 months ago

You don't give enough information to reproduce the issue or even figure out what you are trying to do or how you are attempting to do it. Looks like you are missing SDL, but who knows?

Ciflire commented 7 months ago

https://github.com/Ciflire/nixpkgs-296692 everything is in here the issue is obtained with the command make ta

sternenseemann commented 7 months ago

You use gcc in the makefile while only clangStdenv is provided.

leon-erd commented 3 months ago

Im also running into the same error using this derivation:

{ pkgs ? import <nixpkgs> {} }:

pkgs.stdenv.mkDerivation {
  name = "solar-sim";

  src = pkgs.fetchFromGitHub {
    owner = "ikalco";
    repo = "solar_system_sim";
    rev = "a78c873fa32c7170807f3fe27216ec1c61b021d4";
    hash = "sha256-JsQwHq80b2pZ1p1vnR3zWMwAwfrgsWo1fLprlqqE0CY=";
  };

  buildInputs = with pkgs; [
    SDL2
    SDL2_ttf
  ];
}

Doesnt matter whether I use stdenv or gccStdenv. If I do not include the libraries in buildInputs I get an error like this:

./src/scenes/scene.h:4:10: fatal error: SDL2/SDL.h: No such file or directory
    4 | #include <SDL2/SDL.h>
      |          ^~~~~~~~~~~~
compilation terminated.

But using the derivation above the error is:

/nix/store/n52asici774chzq897pzdbxfb78myf3d-SDL2_ttf-2.22.0/include/SDL2/SDL_ttf.h:39:10: fatal error: SDL.h: No such file or directory
   39 | #include "SDL.h"
      |          ^~~~~~~

So to me it seems that the compiler has no problem finding the libraries included in the source files of the repo but somehow cannot compile SDL2_ttf itself. What am I missing?

reckenrode commented 3 months ago

This isn’t an issue with SDL2_ttf in nixpkgs. The project you’re trying to build isn’t using pkg-config to locate the SDL2_ttf headers. If it did, the path to SDL2 would also be added automatically.

You can fix this by setting env.NIX_CFLAGS_COMPILE in your derivation to -I${lib.getDev SDL2}/include/SDL2. You also add pkg-config as a nativeBuildInput then either patch the Makefile to invoke pkg-config --cflags SDL2_ttf or update NIX_CFLAGS_COMPILE with its output in preBuild in your derivation.

leon-erd commented 3 months ago

Worked! Thanks for the info!!! :blush: