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.
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

2 Answers 2

up vote 7 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.

g++

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.

-Wall

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

-I/usr/local/include/thrift

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.

*.cpp

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

-lthrift

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

 
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.