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

Discussion in 'C Programming' started by ganesh.kundapur@gmail.com, Jun 21, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. Ian Collins Guest

    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.
    Ian Collins, Jun 21, 2007
    #2
    1. Advertising

  3. Guest

    On Jun 21, 1:23 pm, Ian Collins <> wrote:
    > 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, 2007
    #3
  4. Ian Collins Guest

    wrote:
    > On Jun 21, 1:23 pm, Ian Collins <> wrote:
    >> 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.
    Ian Collins, Jun 21, 2007
    #4
  5. "" <> writes:
    > 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) <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"
    Keith Thompson, Jun 21, 2007
    #5
  6. Chris Hills Guest

    In article <>,
    "" <> writes
    >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 /\/\/\/\/
    /\/\/ www.phaedsys.org \/\/\
    \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
    Chris Hills, Jun 21, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AP  No spam
    Replies:
    5
    Views:
    29,503
    ronynaidu84
    Oct 6, 2011
  2. Nagaraj
    Replies:
    1
    Views:
    837
    Lionel B
    Mar 1, 2007
  3. Andy B
    Replies:
    7
    Views:
    347
    Damien
    May 30, 2008
  4. fAnSKyer
    Replies:
    2
    Views:
    516
    Alf P. Steinbach
    Jun 7, 2009
  5. Andreas Leitgeb

    compile directly into a .zip/.jar file?

    Andreas Leitgeb, Apr 12, 2014, in forum: Java
    Replies:
    22
    Views:
    176
    Arne Vajhøj
    Apr 16, 2014
Loading...

Share This Page