Pages

Thursday, December 20, 2012

Complile C program in Ubuntu


  1. In the terminal, type:
    
    sudo apt-get install build-essential
    
    
  2. Create a main directory called cprog and a sub directory called helloworld to hold the C programs
    
    mkdir -p cprog/helloworld
    
    
  3. Go into that directory
    
    cd cprog/helloworld
    
    
  4. Open a file called main.c in gedit editor
    
    gedit main.c
    
    
  5. Type the following in main.c
    
    #include
    #include
    int main()
    {
    printf("\nHello World,\nWelcome to my first C program in Ubuntu Linux\n\n");
    return(0);
    }
    
    
  6. Save and exit
  7. To compile the program, go into the respective directory, as described in step3
  8. Then type:
    
    gcc -Wall -W -Werror main.c -o helloworldC
    
  9. To execute type:
    
    ./helloworldC
    

No comments: