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.
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
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:
- Install SFML on your system ;D, check your package manager (Recommended), or try typing "make install" on your SFML source directory this will just copy your "lib" and "include" directories to "/usr/local/" which is one of the many directories Linux programs look for libraries.
- Set LD_LIBRARY_PATH variable before running:
LD_LIBRARY_PATH=<library_path> ./main
- Using ld, which I don't remember how to use it, but there plenty information on it's manual: type "man ld" on your terminal
- Similar to using ld, when compiling use -Wl option like this: "-Wl,-rpath=<library_path>" (Never use spaces), this is explained on "ld"'s manual, this pass an option to the linker, it tells you program where to look for the library files.
For example:
g++ -Wl,-rpath=<library_path> -o prog $(LIB_PATH) $(LIBS)