Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Why would you do

g++ -Wall -I/usr/local/include/thrift *.cpp -lthrift -o something

instead of:

g++ -Wall -I/usr/local/include/thrift -c Something.cpp -o something.o
g++ -Wall -I/usr/local/include/thrift -c Something_server.cpp -o server.o
g++ -Wall -I/usr/local/include/thrift -c your_thrift_file_constants.cpp -o constants.o
g++ -Wall -I/usr/local/include/thrift -c your_thrift_file_types.cpp -o types.o

and then:

g++ -L/usr/local/lib -lthrift *.o -o Something_server

Am I right that the first step does essentially the same thing as the second sequence?

Also, to make them identical should something be Something_server in the first line?

share|improve this question
3  
Shouldn’t your question be the other way round? As it is, the answer is trivial: “because it’s five times shorter”. –  Konrad Rudolph May 24 '11 at 8:33
add comment

1 Answer 1

up vote 14 down vote accepted

You're right that you'll end up with the same executable at the end (albeit with a different name); in the first case gcc will actually create a bunch of temporary object files that it removes after linking, versus the second case where you're making the object files yourself.

The main reason to do things the second way is to allow for incremental building. After you've compiled your project once, say you change Something.cpp. The only object file affected is something.o -- there's no reason to waste time rebuilding the others. A build system like make would recognize that and only rebuild something.o before linking all the object files together.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.