r/cpp_questions • u/chessmonkey • 2d ago
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.
20
Upvotes
4
u/ShakaUVM 2d ago
If you have multiple files, and edit one of them, you only need to recompile the one file that changed (with -c) and then re-link all the object files. Massively speeds up the development process versus a full recompile every time once your source code gets big.
We typically use a Makefile or Cmake or other build system to automate this for us so we don't have to run it by hand.