Compiling C codes in Ubuntu

5,077

You can compile from following command :

$ gcc -o object-file C-source-file

Then try to run :

$ ./object-file

For C code you can use cc command too also you can use g++ for C++.

Once your code becomes more complicated and you start using more and more files, the above will become cumbersome and you'll want to look into "makefiles". They work for small projects too, so the sooner you become familiar with them, the better. If you later code in C++, you will also likely use these.

Share:
5,077

Related videos on Youtube

André Monteiro
Author by

André Monteiro

Updated on September 18, 2022

Comments

  • André Monteiro
    André Monteiro over 1 year

    I'm a rookie programmer and trying to compile a C code in Ubuntu. I already installed GCC. How do I proceed from here?

  • SilverWolf
    SilverWolf over 6 years
    Shouldn't c-fileName go directly after the -o?
  • Rajat Jain
    Rajat Jain almost 6 years
    Yes, you are right. Sorry, for the typo error.
  • Chai T. Rex
    Chai T. Rex over 5 years
    For every level of indentation, code blocks require four more spaces. In this case, you have one level of indentation with the numbered list, so you need eight spaces.