≡ Menu

How you can run a c program in Linux?

Q. I've a c program and I'd like to run in Linux.

A. C program need to compile and run in Linux using cc or gcc command. When you invoke GCC (GNU C Compiler), it normally does preprocessing, compilation, assembly and linking for you. For example to compile hello.c program , type the following command:
cc -o hello hello.c
gcc -o hello hello.c

It will compile and produced an exectuable file called hello. To run program type:

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 11 comments… add one }

  • Felix Mwango Mutale March 27, 2009, 1:46 pm

    Hello All,

    I need help. I have a ‘C’ program that was compiled on SCO OpenServer 5.05 and now want to compile on Linux Red Hut. This is failing to compile. Here is part of the program:
    #define MENU_WD 5
    #define MENU_HT 19
    #define MENU_HP 27
    #define MENU_VP 5


    struct s_menus{
    int ops;
    int y,x,w,o;
    int ptr;
    char title[20];
    char *options[10];
    typedef struct s_menus MENU;

    MENU m;
    int i;
    char a[20];

    menus_op(&m, “Student Records”);
    menus_op(&m, “Chameleon 2000”);
    menus_op(&m, “Change Password”);
    menus_op(&m, ” Exit”);


    How can I make this compile and run ?

    Thanking you in advance.

    Felix Mwango Mutale

  • hehehe April 8, 2010, 2:26 am

    that’s very easy, just shut down your computer =)) lol

  • jadaces June 25, 2010, 7:22 am

    Try adding a header file to #include eg: #include

    main() has to be declared with a return value eg: void, int, char,

    put int main(){}

    compile now and see what happens.

  • Felix Mwango Mutale October 1, 2010, 1:44 pm

    Dear Sir,

    I have been struggling to get bold letters in informix for CentoS 4.8 and how can I use PCL Command Sequences to solve this problem ?

    I have the following declarations and print command in my informix-4gl but things don’t seem to get right.

    BoldOn CHAR(6),
    BoldOff CHAR(6)

    —-LET BoldOn = ASCII 27, ASCII ‘&040’, ASCII ‘&115’, ASCII ‘&052’, ASCII ‘&066’
    —-LET BoldOff = ASCII 27, ASCII ‘&040’, ASCII ‘&115’, ASCII ‘&048’, ASCII ‘&066’

    LET BoldOn = ASCII 27,”(s4B”
    LET BoldOff = ASCII 27,”(s0B”

    COLUMN 54, BoldOn CLIPPED, ” “, “Ref: “, BoldOff CLIPPED, r_refno

    PRINT COLUMN 1, BoldOn CLIPPED, ” “, “This is to certify that: “, BoldOff, r_surname, ” “, r_firstname

    and this what I am getting:

    ^[(s4B TO WHOM IT MAY CONCERN^[(s0B ^[(s4B Ref: ^[(s0B 9844510
    ^[(s4B This is to certify that: ^[(s0B NAMONJE CAROL
    ^[(s4B is a registered student of the National Institute of Public Administration^[(s0B

    We have HP LaserJet P3005 and P3015 Printers.

    How can I avoid printing these charaters and instead print Bold letters ? Are there any settings I need to do in Environmental variables or CUPS settings ?

    Your help will highly be appreciated.

    Felix Mwango Mutale

    • priya October 10, 2011, 7:00 am

      yum install gcc is not working

      • Rahul July 29, 2013, 7:38 pm

        try this
        sudo yum install gcc-c++

  • yogakumar April 6, 2012, 9:04 am


  • akash mishra August 1, 2012, 7:05 am

    i have a compiled c file,i want to execute it and see its result on html page,like in gnome we type ./file name,then we can see the output but i dnt want to do this,i want to make it through html page,thats by click the ouptu should comew hw to do

  • Rahul July 29, 2013, 7:39 pm

    sudo yum install gcc-c++

  • dhanya February 20, 2014, 11:43 am

    I have linux mint os.how to compile two or more programs using make file?

  • sooraj March 31, 2014, 8:50 am

    when i compile my c program in ubuntu terminal using gcc..its says no such directory found..can u help me

Leave a Comment