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.
Any help would be great
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++
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With