How to compile c++ with SFML library within the project itself

Asked

Viewed 319 times

1

Hello people who like to program. I have a problem that so far searching on the father of donkeys (Google) I could not solve. I’m doing a little game as part of the evaluation of the programming language course 1. but I don’t know how to link (compile) correctly the game, with the SFML library inside the project folder. I installed SFML on linux (Elementary) and am compiling directly by codeblocks, only I want to make a Makefile to compile the project in order to also use the library within the project folder, so that even those who do not have the sfml installed on the computer can compile without problems. I know that when the sfml is installed we compile more or less like this.

g++ -Wall src/main.cpp src/game.cpp -I include -o bin/app -lsfml-system -lsfml-window -lsfml-graphics

but it only works if the library is installed in the system. Is there any way I can make a lib folder and put SFML there and compile it? I hope my doubt was clear. a hug to all.

1 answer

1

Yes, just use the path from where the lib is that you want to use with the -L + directory argument

g++ -Wall src/main.cpp src/game.cpp -I include -o bin/app -L lib/SFML-2.3.2 -lsfml-system -lsfml-window -lsfml-graphics

Just remember that libs should be distributed together with binary if they are linked dynamically.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.