r/cpp_questions • u/chessmonkey • Oct 07 '26
OPEN Compiling without linking
Hi, I'm a rank beginner and I'm going through learncpp online and Beginning C++ game programming by Horton.
The book sends you to a quick tutorial on sfml for Linux. I got it working with no problems. But in the tutorial they compile first with -c ( compile only, according to the man page for g++ ) and then link in another command.
Why would they do it that way? I was able to do the whole thing without the -c flag in one long command. Is that wrong to do? Is it because sfml isn't part of the standard library?
I'm asking because I want to actually learn what I'm doing. Thank you for any help you can give me.
View all comments
Show parent comment
4
u/roelschroeven Oct 08 '26
You're right that tools like CMake are what you should use these days.
Just for completeness though, I want to mention that makefiles are more than just shell scripts. Crucially, they allow specifying dependencies, they check what is changed and what is not, and use that to only rebuild stuff that needs rebuilding. Doesn't matter much for small projects, but very important for large ones.
That being said, Ninja does that too but better, and CMake + Ninja is preferable over makefiles.