Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating object file to separate directory using g++ compiler - C++

Tags:

c++

g++

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 could I write it?
  2. How can I see the compiler switches supported by g++ and it's usages?

Any help would be great

like image 974
Navaneeth K N Avatar asked Apr 23 '09 14:04

Navaneeth K N


2 Answers

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

like image 114
dirkgently Avatar answered Oct 08 '22 22:10

dirkgently


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
like image 27
Doug T. Avatar answered Oct 08 '22 22:10

Doug T.