tags:

views:

1291

answers:

3

I use the following code to compile a cpp file to object file.

g++ -c main.cpp

Above code generates the .o fles in same directory where main.cpp resides.

  1. Suppose I have a folder named obj and need to generate the object files there, how do I write?
  2. How can I see the compiler switches supported by g++ and it's usages?

Any help would be great

+5  A: 

Suppose I have a folder named obj and need to generate the object files there, how do I write?

Use:

g++ -c main.cpp -o obj/main.o

How can I see the compiler switches supported by g++ and it's usages?

If you are on a *nix system use:

man g++

or use info g++

dirkgently
not to be a jerk but you kind of just edited your question and added more detail about man pages that I already had in my original question.
Doug T.
I hadn't seen your post till I committed my edit.
dirkgently
ok I'll give you the benefit of the doubt.
Doug T.
One more thing, if you note, I mentioned the system man as opposed to the online collection and info. These were missing. I did see your edit after making the edit and did not re-edit since I think our answers _combined_ more or less a completely says whatever there is to say. But you are right to believe otherwise.
dirkgently
sounds like some kind of collaborative answer with point sharing would be helpful in this kinda situation, eh?
veefu
Thanks. That worked.
Appu
+6  A: 

If you type

$man g++

Here's the man page online You'll probably get gobs of good information there. You can also try

$g++ --help

To your question. If you used the -o switch, you can specify the output file to use. So you could probably do something like

$g++ -c main.cpp -o obj/main.obj
Doug T.
+1. Good answer. (Dunno why this isn't voted up!)
dirkgently
+1  A: 

Another answer to question 2: More information about the compiler switches can be found in the online manual.

palm3D