3

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

5

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.

| improve this answer | |
0

In a terminal (press Ctrl+Alt+T to open one):

  1. Change the directory to where you have saved the .c file using

    cd path
    

    command

  2. Type the following command and change the fileName with yours

    gcc -o c-fileName fileName.c
    

    You can write any name instead of c-fileName.

  3. Then to run your file type

    ./c-fileName
    

    in terminal.

| improve this answer | |
  • Shouldn't c-fileName go directly after the -o? – SilverWolf - Reinstate Monica Jan 18 '18 at 18:48
  • Yes, you are right. Sorry, for the typo error. – Rajat Jain Jun 5 '18 at 19:59
  • 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. – Chai T. Rex Sep 24 '18 at 11:14
0

or you can compile your f.c file from console:

gcc f.c -Wall

then run :

./a.out
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.