By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,463 Members | 774 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,463 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
--
ld: warning: cannot find entry symbol _start; defaulting to 080481a4
--
linking face creates a binary a.out. When i tried to execute it, I'm
getting
--
bash: ./a.out: /usr/lib/libc.so.1: Bad ELF interpreter: No such file
or directory
--

As per the ld man page, we need to link the object file with the
crt0.o and libc, but i didnt find crt0.o in /lib nor in /usr/lib.
Please let me know how to do this.

--
Ganesh

Jun 21 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ga*************@gmail.com wrote:
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!

--
Ian Collins.
Jun 21 '07 #2

P: n/a
On Jun 21, 1:23 pm, Ian Collins <ian-n...@hotmail.comwrote:
ganesh.kunda...@gmail.com wrote:
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!

--
Ian Collins.
I just wanted to know how the compiler does all these at one go.

Jun 21 '07 #3

P: n/a
ga*************@gmail.com wrote:
On Jun 21, 1:23 pm, Ian Collins <ian-n...@hotmail.comwrote:
>ganesh.kunda...@gmail.com wrote:
>>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!
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.

--
Ian Collins.
Jun 21 '07 #4

P: n/a
"ga*************@gmail.com" <ga*************@gmail.comwrites:
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>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 21 '07 #5

P: n/a
In article <11**********************@j4g2000prf.googlegroups. com>,
"ga*************@gmail.com" <ga*************@gmail.comwrites
>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.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Jun 21 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.