1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Compile C code in Linux

Discussion in 'C' started by Tlhokomelo, Sep 10, 2006.

  1. Tlhokomelo

    Tlhokomelo New Member

    Joined:
    Sep 10, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Please help, I am leaning C on my own so you are my only Hope
    I am using that "The C programming Language" E-book but it does not teach how to compile in linux - I was too long ago when those Bell Lab guys wrote it

    I am using the GNU gcc compiler, I find it hard to work with it.
     
  2. Essial

    Essial New Member

    Joined:
    Sep 12, 2006
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    gcc is pretty easy. Just say "gcc --help" in a graphical console and look at all the options, OR if your in console, pipe the output to less by saying "gcc --help | less" to see all the options. But in general I think, for console apps, I just say "gcc myfile.c -o myapp" or whatnot. Also, if your doing C++ you may be using gpp instead of gcc. Let me know if this doesn't help.
     
  3. Tlhokomelo

    Tlhokomelo New Member

    Joined:
    Sep 10, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Thanks Essial
     
  4. Essial

    Essial New Member

    Joined:
    Sep 12, 2006
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    Assuming you are new to Linux in general, and also assuming you aren't using Gentoo, you may be unfamiliar with makefiles. Linux has a "make" tool that executes a makefile, which is a glorified batch:

    Code:
    compile:
      gcc main.c -o app
    clean:
      rm app
    
    then you can say "make clean" or "make compile" or whatnot. You may want to read up on this.. its an invaluable tool as far as programming in linux goes.
     
  5. Tlhokomelo

    Tlhokomelo New Member

    Joined:
    Sep 10, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Yes I am quite new the programming and I am still in the elementary chapeter of the above book. Your help is highly appreciable.
     
  6. Vineel567

    Vineel567 New Member

    Joined:
    Nov 23, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    hi......



    gcc test.c

    will compile ur program and create an executable file named a.out
    and run that program by issuing

    ./a.out
     

Share This Page