Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Makefile cannot find -lsfml-XXX  (Read 1651 times)

0 Members and 1 Guest are viewing this topic.

tjktak1002

  • Newbie
  • *
  • Posts: 2
    • View Profile
Makefile cannot find -lsfml-XXX
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Makefile cannot find -lsfml-XXX
« Reply #1 on: April 29, 2022, 09:33:47 am »
LIBRARY_PATHS should start with -L instead of -I.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

tjktak1002

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Makefile cannot find -lsfml-XXX
« Reply #2 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Makefile cannot find -lsfml-XXX
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BasNorth

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: Makefile cannot find -lsfml-XXX
« Reply #4 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:
  • 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:
Code: [Select]
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:
Code: [Select]
g++ -Wl,-rpath=<library_path> -o prog $(LIB_PATH) $(LIBS)

 

anything