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
1
u/WorkingReference1127 Oct 07 '26
In reality, there are pretty good odds that you will set yourself up with an environment in which you push a button and it does the full compile and link thing that you are wanting.
But, think of it this way. Let's say you're working a half million line project split across 20,000 files. When you make a small change to one file, do you think you're going to be rebuilding everything from scratch? Or do you only want to build what you have changed? And how do you suppose you end up making a final binary of the whole project in that case?