Thread: Compiling a C program in Linux

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    53

    Compiling a C program in Linux

    Hey guys..I'm setting up redhat 9 or mandrake 9 tonight on this old pentium 1 133mhz...How do you compile c/c++ compilers...I know how to type them in the VI editor but then what do I do from the terminal??

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    It depends on what compiler you have. Linux will probably come with GCC equipped, so you can simply do this to compile and run a program you've written:
    Code:
    $ gcc prog.c
    $ ./a.out
    Note that you have to be in the same directory as the .c file.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Jun 2003
    Posts
    53
    How will I run it though after compiling?

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >How will I run it though after compiling?
    ./a.out

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >How will I run it though after compiling?
    Did you do everything I suggested? If you did then it would compile and run for you.
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    23
    I always do
    Code:
    gcc -ggdb -Wall prog.c -o prog
    ggdb and Wall are just precautions and -o prog is for when you want to keep your executable after your next compile. If you keep the a.out, it'll be overwritten next time you compile a programme.
    and you run it :
    $ ./prog
    Last edited by Cikotic; 06-28-2004 at 07:02 PM.
    If pointers have made you suicidal, you're not alone. But there is no need to hurt yourself. There are people who are willing to help. Just call your local C Crisis Centre and talk to the professtionals there. If you don't have a C3 in your neighborhood, go to the global C3 at www.cprogramming.com . If you're still suicidal, don't lose hope. Gently close your book on C and throw it in the fireplace. If you live in a tower, you can throw it out the window. There, doesn't that feel better?

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >ggdb and Wall are just precautions
    It never hurts to throw -ansi and -pedantic in there too.

    >gcc -ggdb -Wall prog.c -o prog
    I think that's just a little complex for someone who just started using the compiler and isn't likely to be using gdb just yet, or able to follow the mass of warnings that will probably appear, but good advice nonetheless.
    My best code is written with the delete key.

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    It never hurts to throw -ansi and -pedantic in there too.
    It does if you are using ANSI unsupported functions

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >It does if you are using ANSI unsupported functions
    I considered mentioning that, but it wouldn't have sounded as good as a rule of thumb. And anybody who's anybody[1] only writes strictly conforming programs.

    [1] Which would pretty much be nobody.
    My best code is written with the delete key.

  10. #10
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    I always throw in -Wall to turn on all warnings.

  11. #11
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I would also recommend throwing in -Werror
    I have yet to see a warning from gcc or g++ that wasn't worth looking at.

  12. #12
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    Quote Originally Posted by hern
    Hey guys..I'm setting up redhat 9 or mandrake 9 tonight on this old pentium 1 133mhz
    I'm curious to know how well it runs on a 133. What WM are you using? I have redhat 9 on a 366 mhz machine running gnome and there is some noticable slowness.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  13. #13
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I'm curious to know how well it runs on a 133.
    With KDE or GNOME, probably not well. With something less sophisticated like twm, it'll probably be pretty zippy.
    My best code is written with the delete key.

  14. #14
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    twm is a bit on the gross side. I can tolerate something like CDE (although the first thing I do to all Solaris boxes is install gnome).

    I guess I'm a spoiled windows guy still. Yes, I do most of my work at the command line now, but there's just something about working in a reasonable window manager. Half the time I just remote stuff to a windows X server anyway so I guess it is moot.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  15. #15
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    time to push fluxbox. I love it Small and fast; I can control keyboard functions(including: windows key...) and multiple desktops.
    Although, I swapped to it from enlightenment. I am still waiting for their release of DR17. Those coders are lazier than most people here. It has been about 2 years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stray Error while compiling
    By Mankthetank19 in forum C Programming
    Replies: 6
    Last Post: 02-03-2011, 03:24 PM
  2. error compiling a little program
    By fbs777 in forum C Programming
    Replies: 4
    Last Post: 03-17-2009, 10:35 PM
  3. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  4. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  5. Replies: 5
    Last Post: 04-10-2006, 03:03 PM