Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
g++ -Wall -I/usr/local/include/thrift *.cpp -lthrift -o something

I am new to Linux and am trying to learn "as I go along"....This is from the Apache Thrift website.

Also is the -I/usr supposed to be -I /usr?

Thanks for your help!

share|improve this question
up vote 8 down vote accepted

Here is a breakdown of the command. First the original command, for reference

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

Now, for the breakdown.


This is the actual command command, g++. It is the program that is being executed. Here is what it is, from the man page:

gcc - GNU project C and C++ compiler

This is a compiler for programs written in C++ and C. It takes C or C++ code and turns it into a program, basically.


This part makes it display all warnings when compiling. (Warn All)


This part tells g++ to use /usr/local/include/thrift as the directory to get the header files from. And with the question about whether to put a space after the I or not. You can do it either way. The way the options (options are things in a command after - signs. -Wall and -I are options) are parsed allows you to put a space or not. It depends on your personal preference.


This part passes every .cpp file in the current directory to the g++ command.


This can also be -l thrift. It tells g++ to search the thrift library when linking.

-o something

This tells it that when everything is compiled to place the executable in the file something.

I hope this helps and please comment if anything is unclear!

share|improve this answer
Thanks!...awesome explanation! – algorithmicCoder May 24 '11 at 1:28

Generally you should look for the documentation of a command in its man page: man g++. In the case of GNU software such as GCC, you'll usually find more complete documentation in info format, or in HTML on the software home page.

C (and C++) compilers have a somewhat peculiar syntax that doesn't heed the usual conventions for options (options come before operand, there's an optional space between an option and its argument, …). The space after -I is actually optional, but -Wall needs to be one word.

Here's a quick overview of that command (look in the documentation for details):

  • g++ run a C++ compiler
  • -Wall emit warnings on suspicious code (-Wall actually means important warnings only, not all possible warnings)
  • -I/usr/local/include/thrift look in that directory for include files (#include directives)
  • *.cpp compile these files
  • -lthrift link with this library (this searches libthrift.a). Note that -l must come after the files you're compiling, because -l means “if there are any undefined symbols at this point, look for definitions in the specificed library”
  • -o something put the compiled and linked output into the specified file
share|improve this answer

Your Answer


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.