I dont know how to compile cpp programs with gcc

S

Sreenivas

I dont know how to compile cpp programs with gcc as i am new to gcc
and cpp.
could anybody help me out?
Thanks&Regards,
Srinivas Reddy Thatiparthy.
 
B

Bo Persson

Sreenivas said:
I dont know how to compile cpp programs with gcc as i am new to gcc
and cpp.
could anybody help me out?
Thanks&Regards,
Srinivas Reddy Thatiparthy.

This group is really about the language, and not about using any
particular tools.

You could start by trying

gcc --help

and be welcome back when you have a program that does not compile or
work properly.


Bo Persson
 
D

david

I dont know how to compile cpp programs with gcc as i am new to gcc
and cpp.
could anybody help me out?
Thanks&Regards,
Srinivas Reddy Thatiparthy.

Use gcc for C and for C++ use g++.

g++ -Wall -ansi -pedantic -o <name> [file1, file2, ...]

But if you want to do it in correct way first of all you should build
Obj files.
g++ -Wall -ansi -pedantic -o <module_name> <module_file>
After you have all modules and main program compiled, link them.
g++ -o <program_name> [file1.o, file2.o, ...]
 
J

James Kanze

I dont know how to compile cpp programs with gcc as i am new
to gcc and cpp. could anybody help me out?

You do it exactly the same way you do with any compiler: you
read the documentation, very carefully, in order to choose the
options which are appropriate to what you're doing. I could
give you the options I use for compiling under Linux, but
there's absolutely no reason to suppose that they would be
appropriate for your circumstances.
 
N

nbaker2328

I dont know how to compile cpp programs with gcc as i am new to gcc
and cpp.
could anybody help me out?

If you use the correct filename extensions on your source files, then
the 'gcc' command will happily compile your C++ code. There is one
caveat -- if you make use of any StdLib functions, you will need to
tell 'gcc' to use the C++ library instead of defaulting to the C one.

From the 'man' page:

" Compiling C++ Programs

C++ source files conventionally use one of the suffixes .C,
..cc, .cpp,.CPP, .c++, .cp, or .cxx; C++ header files often use .hh
or .H; and preprocessed C++ files use the suffix .ii. GCC
recognizes files with these names and compiles them as C++ programs
even if you call the com$B!>(Bpiler the same way as for compiling C
programs (usually with the name gcc).

However, C++ programs often require class libraries as well as
a compiler that understands the C++ language---and under some
circumstances, you might want to compile programs or header files from
standard input, or otherwise without a suffix that flags them as C++
programs. You might also like to precompile a C header file with a .h
extension to be used in C++ compilations. g++ is a program that calls
GCC with the default language set to C++, and automatically specifies
linking against the C++ library. On many systems, g++ is also
installed with the name c++."

Nathan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top