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

This is from the Apache Thrift website.

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

2 Answers 2


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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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