By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,730 Members | 1,540 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,730 IT Pros & Developers. It's quick & easy.

How to use Makefile to compile a project with multiple files ?

P: 8
Recently i've just built an SFML/C++ project on Visual Studio Code using CMake and MinGW.I've successfully compiled and run a test file in my project folder.

Here's my Makefile:

Expand|Select|Wrap|Line Numbers
  1. StarFire:
  2.     g++ main.cpp -o main.exe -DSFML_STATIC    -I F:\SFMLPrj\StarFirestc\Prefixes\include    -L F:\SFMLPrj\StarFirestc\Prefixes\lib    -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -lfreetype
But then when i include more files into the folder i don't know how to modify my Makefile to compile 2 or more files.

Basically when i run my test file for the first time,i include SFML header into that test file so when the compiler(MinGW) runs,it looks into the Makefile and know that i've included SFML headers there.But when i make a new class in the folder(Game.h and Game.cpp) i put the SFML into the 'Game.h' file then include it in the test file.

Not only i don't know how the compiler would look for SFML headers and libs from now on.I also don't know how it will look for the 'Game' class and a bunch of other classes i will make in the future.

Can anyone help me ?
2 Weeks Ago #1
Share this Question
Share on Google+
1 Reply


P: 8
Finally solve the problem,so not only do you have to link the SFML headers and library to the .exe file,the obj file also have to be linked.I just put the linking instructions(DSFML_STATIC) in front of the .o file recipe and my project compiles successfully.
2 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.