How to compile a C source file without using the C compiler directly

G

ganesh.kundapur

Hi,
I want to know how to compile the C source file without using the
compiler directly. I mean to say by using compiler componets such as
( cpp, cc, as, ld ).
I tried to compile the fallowing code as fallows
file name: hello.c
# include <stdio.h>

int
main ( void )
{
printf ( "Hello World\n" );

return 0;
}

cpp hello.c hello.i // Preprocessing
cc -S hello.i // Assembly code generating
as -o hello.o hello.s // generate m/c code
ld -o a.out hello.o -lc // linking

In linking phase, I'm getting warning saying that
 
I

Ian Collins

Hi,
I want to know how to compile the C source file without using the
compiler directly. I mean to say by using compiler componets such as
( cpp, cc, as, ld ).

Time for some off topic advice - don't do it!
 
I

Ian Collins

Please don't quote signatures.

I just wanted to know how the compiler does all these at one go.
For that you'd have to ask on a platform/compiler specific group.
 
K

Keith Thompson

I want to know how to compile the C source file without using the
compiler directly. I mean to say by using compiler componets such as
( cpp, cc, as, ld ).
[snip]

This is a question about your compiler, not about the C language.

Some compilers may have an option to display the steps it goes through
to compile and link your code. Consult your compiler's documentation.

<OT>If you're using gcc, try the "-v" option; "info gcc" for
details.</OT>
 
C

Chris Hills

Hi,
I want to know how to compile the C source file without using the
compiler directly. I mean to say by using compiler componets such as
( cpp, cc, as, ld ).
cpp hello.c hello.i // Preprocessing
cc -S hello.i // Assembly code generating
as -o hello.o hello.s // generate m/c code
ld -o a.out hello.o -lc // linking

This is compiler specific. However all C compilers generally follow the
same steps.

Incidentally at one time compilers used to be 3 pass so your cc step
would have been
cc1
cc2
cc3

what has happened over the years is the three parts of the compiler have
been merged into one and in most the pre-processor as well.

They used to be separate because there was not enough memory etc to do
the whole lot at once and floppy disks held 360K (what hard disk?) . A
compiler/assembler/linker might be on three separate floppies.

These days the compiler will be able to "store" the temp files in memory
or quickly on the hard disk. Also the whole compiler can be called from
hard disk without having to swap floppies.

Many compilers are now "single pass" with the CPP and turn our object
code completely missing the assembler phase. So you would have
cc
ld

For your question MAKE was invented.

You call MAKE with a make file.

You have to write the makefile yourself, just the once and in future it
will call the compiler parts and the appropriate files.

Otherwise you could use a batch file or script. (This is al very basic
stuff)

Modern compiler suites use an IDE and that hides the makefile (or does
it's own similar thing) and compiler but under the covers it too calls
the compiler, linker assembler as above. Though in some compiler suites
they will be DLL's rather than stand alone exe programs with a command
line.

However you should have covered this in your initial programming
classes.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top