.: Most Read :.

Join Churp Churp

Join Churp Churp
Click on the image to find out more
Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Thursday, November 07, 2013

Tutorial: Simple C in Linux (Ubuntu)

Create, and compile simple C file on Linux terminal.

Requirement:

You have updated and upgraded your Linux OS.

sudo apt-get update

sudo apt-get upgrade

Installed gcc

sudo apt-get install gcc

Installed make (optional)

sudo apt-get install make

 

Steps:

Login to your Linux machine.

vi sampleC.c

Press I to enter Insert mode.

Type the following C source code:

#include<stdio.h>

void main(void)

{

printf("Hello world\n");

}

Done with writing the source code.

Press Esc

Then :wq [write and quit vi tool]

To compile, you can do this in many ways;

Method 1 – direct compilation

gcc sampleC.c -o sampleC

or

Method 2 – compile using makefile

create a new make file

vi sampleMakefile

Type the following commands in makefile:

#applicationFile

all: sampleC

#.o file

   sampleC: sampleC.o

   gcc -o sampleC.o

#.c file

   sampleC.o: sampleC.c

   gcc -o sampleC.c

Done with writing the commands in makefile.

Note:

You may replace “sampleC” by using your own filename.

# is used for command.

Press Esc

Then :wq [write and quit vi tool]

Execute the make file

make -f sampleMakefile

Make sure there is no error.

Now, your program is ready to be executed.

./sampleC

Sample output:

Hello world

Thursday, April 12, 2012

Morning call

8.20am

phone is ringing

Caller: "How are you doing?" bla.. bla... bla... "I want you to study about scientific LINUX"... "probably with MPI"

Of course no problem... my former supervisor who's going to be my future-colleague! I am glad you did tell me earlier.


will say hello to these monsters again.

Bismillah.