Reputation: 23
I am trying to use nixOS to build a gtk4 application that requires glib. When running a nix-shell with the following shell.nix:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = with pkgs.buildPackages; [
libgcc
glib
clang-tools
];
}
And the following main.cpp:
#include <glib-2.0/glib.h>
int main(){ }
Running g++ main.cpp
returns
/nix/store/f8y44c3k32piprp8wj999cdlakpz86kz-glib-2.80.2-dev/include/glib-2.0/glib.h:32:10: fatal error: glib/galloca.h: No such file or directory
32 | #include <glib/galloca.h>
| ^~~~~~~~~~~~~~~~
compilation terminated.
Also, another dependency (shumate) seems to expect the header file #include <glib.h>
, but glib in a nix-shell seems to instead provide #include <glib-2.0/glib.h>
How can I correctly use glib in a nix-shell for development? Thank you
Upvotes: 1
Views: 167
Reputation: 59
You might need to explicitly specify the directories for headers packages.
example:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = with pkgs; [
glib
clang-tools
];
# Add additional environment variables if needed
NIX_CFLAGS_COMPILE = [ "-I${glib.dev}/include" ];
NIX_LDFLAGS = [ "-L${glib.lib}" ];
# Set the PKG_CONFIG_PATH to include pkg-config files for glib during build
PKG_CONFIG_PATH = "${glib.lib}/pkgconfig";
}
The -I${glib.dev}/include flag ensures that the compiler can find the Glib headers; The -L${glib.lib} entry ensures that the linker knows where to look for the libraries;
Upvotes: 2