SFML community forums

Help => General => Topic started by: tjktak1002 on April 29, 2022, 09:21:03 am

Title: Makefile cannot find -lsfml-XXX
Post by: tjktak1002 on April 29, 2022, 09:21:03 am
Hello everyone, I am trying to implement a Makefile for my SFML project but I am running in to the problem of not the compilator not being able to find -lsfml

This is my Makefile in which main.cpp and menu.cpp requires SFML
all: main

LIBS=-lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system

#INCLUDE_PATHS specifies the additional include paths we'll need
INCLUDE_PATHS = -I/home/tp-home011/07423cc3-2cb5-4121-a984-6deee5e7a545/SFML-2.5.1/include

#LIBRARY_PATHS specifies the additional library paths we'll need
LIBRARY_PATHS = -I/home/tp-home011/07423cc3-2cb5-4121-a984-6deee5e7a545/SFML-2.5.1/lib

main: animal.o coord.o ensemble.o grille.o population.o jeu.o menu.o main.o
        g++ -std=c++11 -Wall $(LIBRARY_PATHS) -o main animal.o coord.o ensemble.o grille.o population.o menu.o jeu.o main.o $(LIBS)

# fichiers objets
main.o: main.cpp
        g++ -Wall -fexceptions -g $(INCLUDE_PATHS) -c main.cpp
animal.o: animal.cpp animal.hpp
        g++ -std=c++11 -Wall -c animal.cpp
coord.o: coord.cpp coord.hpp
        g++ -std=c++11 -Wall -c coord.cpp
ensemble.o: ensemble.cpp ensemble.hpp
        g++ -std=c++11 -Wall -c ensemble.cpp
grille.o: grille.cpp grille.hpp
        g++ -std=c++11 -Wall -c grille.cpp
population.o: population.cpp population.hpp
        g++ -std=c++11 -Wall -c population.cpp
jeu.o: jeu.cpp jeu.hpp
        g++ -std=c++11 -Wall -c jeu.cpp
menu.o: menu.cpp menu.hpp
        g++ -Wall -fexceptions -g $(INCLUDE_PATHS) -c menu.cpp

test: test.o coord.o
        g++ -o test test.o coord.o
test.o: test.cpp coord.hpp
        g++ -std=c++11 -Wall -c test.cpp

clean:
        rm -f *.o main



And this is the log output

/usr/bin/ld : cannot find -lsfml-audio
/usr/bin/ld : cannot find -lsfml-graphics
/usr/bin/ld : cannot find -lsfml-window
/usr/bin/ld : cannot find -lsfml-system
collect2: error: ld returned 1 exit status
make: *** [Makefile:20 : main] Erreur 1
 

Thank you for reading my question.
Title: Re: Makefile cannot find -lsfml-XXX
Post by: eXpl0it3r on April 29, 2022, 09:33:47 am
LIBRARY_PATHS should start with -L instead of -I.
Title: Re: Makefile cannot find -lsfml-XXX
Post by: tjktak1002 on April 29, 2022, 09:56:43 am
Wow, that fix this problem but now I am running into
./main: error while loading shared libraries: libsfml-graphics.so.2.5: cannot open shared object file: No such file or directory
 
I searched on Google that I need to do something with "sudo ldconfig" but without admin premission that seems impossible for me  :P
Title: Re: Makefile cannot find -lsfml-XXX
Post by: eXpl0it3r on April 29, 2022, 10:26:44 am
I forgot how Linux shared library loading order is exactly.
If you can't install it to a shared space (due to missing admin rights), you can try to put the *.so files next to the executable.
If that doesn't work, you could build with RPATH set, so the libraries are searched in the RPATH location.
Title: Re: Makefile cannot find -lsfml-XXX
Post by: BasNorth on May 14, 2022, 06:56:34 am
Wow, that fix this problem but now I am running into
./main: error while loading shared libraries: libsfml-graphics.so.2.5: cannot open shared object file: No such file or directory
 
I searched on Google that I need to do something with "sudo ldconfig" but without admin premission that seems impossible for me  :P

Your program can't find the library files, I presume you have compiled SFML from source. If for some reason you don't want to install it on your system you can try these:
Code: [Select]
LD_LIBRARY_PATH=<library_path> ./mainFor example:
Code: [Select]
g++ -Wl,-rpath=<library_path> -o prog $(LIB_PATH) $(LIBS)