GCC Compling

Okay, so I've successfully installed GCC on Mac 10.6.8 Snow Leopard. But once it's installed and stuff, how do you use it to compile a program? I have the program I want to run in a nice .cpp file in my main directory. Please help, I know I sound like a dork, but I can't find out how to compile a .cpp file.
Command line!

Basic format:
g++ <input_files>


A few handy flags (add these before your input files):

To choose an output file:
-o <output_file_name_and_path>


To follow the standard strictly:
-pedantic


To give more warnings as to what you might be doing wrong:
-Wall


To suppress warnings:
-w


To add debug information that GDB might be interested in:
-g


To link with a library (standard library is linked with by default):
-l<library_name>


To add a directory to search for libraries:
-L<library_path>


To add a directory to search for headers:
-I<include_path>


To compile a file without linking it against anything:
-c


To enable optimization (do not use unless you're sure the program works):
-O<0, 1, 2>


Enjoy!

-Albatross
Is it a Terminal command?
closed account (Dy7SLyTq)
not all of them. the first is and then everything after is the flags
Yes.
Esample (see Albatross answer for more detailed infos):

step1: compile only (create an object file)
 
g++ -c -o obj_file.o source_file.cpp


step2: linking (produces the final "binfile")
 
g++ -o binfile main.o obj_file.o objfile2.o ...
Topic archived. No new replies allowed.