Thread: How to compile C program in Linux?

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    22

    How to compile C program in Linux?

    I'm a beginner to use Linux OS. I don't know how to compile and run a C program in Linux. Can anyone help one?

  2. #2
    Registered User HaLCy0n's Avatar
    Join Date
    Mar 2003
    Posts
    77
    C++: g++ -o executable source.cc
    C: gcc -o executable source.c

    If you don't specify the object file with -o, it defaults to a.out.

    For more information on all of the different options: man gcc

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    22

    Thank you for your reply. One more question......

    Can you explain more about what means of 'If you don't specify the object file with -o, it defaults to a.out.'?

    Also, if i have a file to pass in the program, how can I do this?

  4. #4
    Registered User HaLCy0n's Avatar
    Join Date
    Mar 2003
    Posts
    77
    The object file is the program. If you just say g++ source.cpp, it will compile the code and make a.out the executable. On the other hand, if you specify one, it will compile and make it.

    g++ -o exec source.cpp, will result in making a file called "exec" as the compiled version of source.cpp.

    As for the file issue, I believe http://faq.cprogramming.com/cgi-bin/...&id=1043284392 should help.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    22

    Thank you

    Thank you for your reply

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 03-10-2008, 12:08 PM
  2. compile time error in example program
    By dragonlady in forum Windows Programming
    Replies: 3
    Last Post: 01-01-2006, 01:44 PM
  3. compile program?
    By Goosie in forum C++ Programming
    Replies: 9
    Last Post: 06-22-2005, 02:26 PM
  4. Running C program in Linux or Windows
    By kepler in forum C Programming
    Replies: 4
    Last Post: 09-30-2003, 08:31 AM