Can't Link SFML Dynamically on NixOS – Only .a Files Available?

I’m trying to use SFML with C++ on NixOS. I enter a development environment using:

nix-shell -p sfml pkg-config

But when I try to compile my code:

$ g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system -lm        
/nix/store/v63bxfiacw082c7ijshf60alvvrpfxsq-binutils-2.44/bin/ld: cannot find -lsfml-graphics: No such file or directory
/nix/store/v63bxfiacw082c7ijshf60alvvrpfxsq-binutils-2.44/bin/ld: cannot find -lsfml-window: No such file or directory
/nix/store/v63bxfiacw082c7ijshf60alvvrpfxsq-binutils-2.44/bin/ld: cannot find -lsfml-system: No such file or directory
collect2: error: ld returned 1 exit status

I checked the library directory for SFML (using pkg-config --variable=libdir sfml-graphics) and noticed that it only contains .a files (static libraries), but no .so files (shared libraries). I want to use dynamic linking(I tried to statically link it dint word more errors), but it seems the SFML package in Nixpkgs is built only with static libraries.

How can I get the .so files or use SFML dynamically in NixOS?

hello , did you find a fix for this , im stuck on the same issue

Things seem to be different now due to sfml: 3.0.0 -> 3.0.1, build shared, fix audio by marcin-serwin · Pull Request #426742 · NixOS/nixpkgs · GitHub :

$ tree result/ -L 2
result/
├── include
│   └── SFML
├── lib
│   ├── cmake
│   ├── libsfml-audio.so -> libsfml-audio.so.3.0
│   ├── libsfml-audio.so.3.0 -> libsfml-audio.so.3.0.1
│   ├── libsfml-audio.so.3.0.1
│   ├── libsfml-graphics.so -> libsfml-graphics.so.3.0
│   ├── libsfml-graphics.so.3.0 -> libsfml-graphics.so.3.0.1
│   ├── libsfml-graphics.so.3.0.1
│   ├── libsfml-network.so -> libsfml-network.so.3.0
│   ├── libsfml-network.so.3.0 -> libsfml-network.so.3.0.1
│   ├── libsfml-network.so.3.0.1
│   ├── libsfml-system.so -> libsfml-system.so.3.0
│   ├── libsfml-system.so.3.0 -> libsfml-system.so.3.0.1
│   ├── libsfml-system.so.3.0.1
│   ├── libsfml-window.so -> libsfml-window.so.3.0
│   ├── libsfml-window.so.3.0 -> libsfml-window.so.3.0.1
│   ├── libsfml-window.so.3.0.1
│   └── pkgconfig
└── share
    └── doc

@mooofin if you have a minimal example please share.

1 Like

girll tysm , it worked now , my friend sent a template

https://github.com/SFML/cmake-sfml-project