Results 1 to 1 of 1

Thread: Compiling C program and creating executable file under Linux / UNIX

                  
   
  1. #1
    Junior Entrepreneur Array
    Join Date
    Feb 2010
    Posts
    12
    Post Thanks / Like
    Rep Power
    0

    Thumbs up Compiling C program and creating executable file under Linux / UNIX







    You need GNU C and C++ compiler for compiling C program and creating an executable file. You can use gcc command to compile program.

    First make sure you have gcc installed:

    Code:
    which gcc
    Output
    Code:
    /usr/bin/gcc
    ok u have C compiler in ur box.. [ if u don't have install gcc ]


    To compile C program you need to use syntax as follows:
    Code:
    gcc -o program-output program.c

    Now Write Our First C Program Under Linux / UNIX

    Use a text editor such as vi or gedit to create a C program called first.c:
    Code:
    $ vi first.c
    Type the following lines (program):
    Code:
    #include <stdio.h>
    int main(void){
    printf("My first C program\n");
    return 0;
    }
    How Do We Compile Our Program?

    To compile C program first.c, and create an executable file called first, enter:
    Code:
    $ gcc -o first first.c
    OR
    Code:
    $ cc -o first first.c
    To execute program first, enter:
    Code:
    $ ./first
    Output:
    Code:
    My first C program

    However, both FreeBSD and Linux support direct make command on C program without writing a make file. Remove, first program using the rm command:

    Code:
    $ rm first
    $ make first
    Output:
    Code:
    cc   first.o   -o first
    Execute program first:
    Code:
    $ ./first
    Last edited by TuxRacer; 02-18-2010 at 01:41 AM.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Php in Unix only?
    By plaqichczj in forum Programming
    Replies: 0
    Last Post: 10-17-2011, 07:49 PM
  2. Creating an xml file via PHP and MySQL
    By plaqichczj in forum Programming
    Replies: 0
    Last Post: 08-28-2011, 11:21 PM
  3. How to show hidden file in cpanel file management tool ?
    By Qfjapipa in forum Free Web Hosting
    Replies: 0
    Last Post: 07-12-2011, 10:43 PM
  4. Linux File Commands
    By vipul2000 in forum Linux
    Replies: 3
    Last Post: 05-02-2011, 05:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •