I'm trying to run an example code with SFML 2.5 on Ubuntu, but without success.

I'm using: VSCode 1.27.0 with the Easy C++ Projects extension on Ubuntu 18.04. The build/run output keep saying that the libsfml-graphics-d.so.2.5 cannot be opened even though it's existis and is in the right directory (the ~/SFML in my case)...

The main.cpp:

#include <SFML/Graphics.hpp>

int main()
    sf::RenderWindow window(sf::VideoMode(250, 250), "SFML works!");
    sf::CircleShape shape(125.f);

    while (window.isOpen())
        sf::Event event;
        while (window.pollEvent(event))
            if (event.type == sf::Event::Closed)


    return 0;

The VSCode Easy C++ Projects extension makes a default Makefile that I've edited like this:

CXX       := g++
CXX_FLAGS := -Wall -Wextra -std=c++17 -ggdb

BIN     := bin
SRC     := src
INCLUDE := /home/<my_username>/SFML/include/
LIB     := /home/<my_username>/SFML/lib/

LIBRARIES   := -DSFML_STATIC -lsfml-graphics-d -lsfml-window-d -lsfml-system-d


run: clean all

$(BIN)/$(EXECUTABLE): $(SRC)/*.cpp
    $(CXX) $(CXX_FLAGS) $^ -o $@ -I$(INCLUDE) -L$(LIB) $(LIBRARIES)

    -rm $(BIN)/*

And I'm keep getting the following console output while trying to build/run:

rm bin/*
g++ -Wall -Wextra -std=c++17 -ggdb src/main.cpp -o bin/main -I/home/<my_username>/SFML/include/ -L/home/<my_username>/SFML/lib/ -DSFML_STATIC -lsfml-graphics-d -lsfml-window-d -lsfml-system-d
./bin/main: error while loading shared libraries: libsfml-graphics-d.so.2.5: cannot open shared object file: No such file or directory
Makefile:16: recipe for target 'run' failed
make: *** [run] Error 127
The terminal process terminated with exit code: 2

I don't think you are linking statically?

What happens if you add:


to you link command?

Alternatively, you could use libsfml-graphics-d.a instead of -lsfml-graphics-d to force static linking. This is probably preferable, as the rest is still linked dynamically.

  • \$\begingroup\$ I've tryed -lsfml-graphics-s-d and I got a number of error messages. Then I've tryed to compile SFML 2.5 from source, and it compiles without complaining. But I've got another ton of diferent error messages from that compiled one while trying to use it. I don't know, I'm about to keep up with version 2.4, at least for now... \$\endgroup\$ – Victoralm Sep 6 '18 at 0:10
  • \$\begingroup\$ No, don't use -l for the lib, list the lib directly as a .a file. \$\endgroup\$ – Bram Sep 6 '18 at 0:18
  • \$\begingroup\$ Got me the same error: cannot be used to make a PIE object; recompile with -fPIC... \$\endgroup\$ – Victoralm Sep 6 '18 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.