Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Tutorial Compiling A C Program[ LINUX ]

D

Dan-Kode

Guest
So, you're starting off in the C Programming-Language. Once a popular Language that is still used but just less used than C++. Well, if you are learning C and you want to know how to Compile your Programs then you've come to the right place.

NOTE: This is a Tutorial for Linux-Systems. It has been tested on Linux Ubuntu 19.04(Linux Kernel 5.0). I cannot confirm if it will work on a MacOS X-System or a Windows-System with MinGW installed(MinGW is required to use C on Windows).

Anyways, let's get started. First, open up your Text-Editor. I'll be using the default Text-Editor that comes with Ubuntu but you can use anything else.

Once you've opened up your Text-Editor, write the following Code:
[CODE lang="c" title="hello.c"]#include <stdio.h>

int main(void) {
printf("Hello world!\n");

return 0;
}[/CODE]

Once you've written that, save your File as hello.c

Now we'll get onto the Compiling part of our Program. When we Compile, we'll then have a Program which we can then run by executing Commands.

First, open up your Terminal. You can search through your Computer for it but to open it faster, just press ctrl+alt+t

Now that you've opened up Terminal, make sure you have GCC(GNU-Compiler-Collection). You'll need GCC to Compile your C-Code. If you don't have it installed then there are plenty of Tutorials online dedicated to installing it on your System.

If you do happen to have GCC or have now installed it, execute the following Command:
gcc hello.c -o hello
This will Compile your C Program which can then be ran in the Terminal. To run your Program, enter the following into Terminal:
./hello
Once you've entered that into Terminal, your Program will run and then "Hello world!" will be displayed in Terminal.

Well, congratulations. You've just compiled your first C Program. See, it wasn't that hard.

Good job!
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom