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:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 11 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
11 comments… add one
  • Felix Mwango Mutale Mar 27, 2009 @ 13:46

    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 Apr 8, 2010 @ 2:26

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

  • jadaces Jun 25, 2010 @ 7:22

    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 Oct 1, 2010 @ 13:44

    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 Oct 10, 2011 @ 7:00

      yum install gcc is not working

      • Rahul Jul 29, 2013 @ 19:38

        try this
        sudo yum install gcc-c++

  • yogakumar Apr 6, 2012 @ 9:04


  • akash mishra Aug 1, 2012 @ 7:05

    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 Jul 29, 2013 @ 19:39

    sudo yum install gcc-c++

  • dhanya Feb 20, 2014 @ 11:43

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

  • sooraj Mar 31, 2014 @ 8:50

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

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum