Programming and Webmasters forum
HomeSearchRecent PostsLoginRegister Contact Us

Username  
Password
Announcing 14th Weekly Contest - From 25 July To 01 August.

Win every week on this forum.

Chek out How To Win?
 

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

Compling c/c++ program in linux

 
webmaster forum
Fracker  Offline
Contest Points: 100
 
New Coder
Posts: 11
Topics: 9
September 04, 2009, 11:06:37 PM

OK you written a program, or found a program on internet, and now you want to compile it on linux... you need to use gcc (which is c compiler) and g++ (which c++ compiler). Most of the options are same on both compilers so i will speak about compiling c program on linux.

Now here is a program which you have written or downloaded from internet, helloworld.c

Quote
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv){
 printf("Hello world\n");
 return 0;
}

Now once i have done with program, i have to compile it. Compilation is the process of converting human readable code into a form which the machine can understand. So to compile the above program, i give the following command on console or shell or terminal i don't know what you call it.

Quote
$ gcc helloworld.c

If there are no syntax errors, the program will be successfully compiled and the compiler will create an executable file named, a.out.  If you want your compiler to give different name then, use this option.

Quote
$ gcc -o hello helloworld.c
Now simply execute it.
Quote
$./a.out

the result will be display.. in this manner you can port your all c or c++ programs in linux.
 
webmaster forum
polas  Offline
*
 
Hacker
Gender: Male
Posts: 1224
Topics: 78
WWW
September 08, 2009, 08:54:13 AM

in this manner you can port your all c or c++ programs in linux.

As long as they are portable programs in the first place

Mesham Type Oriented Parallel Programming Language
Skydive in North East England
 
webmaster forum
Admin  Offline
*
 
Hacker
Location: India
Gender: Male
Posts: 1101
Topics: 94
Technical_Talk
WWW
September 08, 2009, 09:01:03 AM

Compilation is the process of converting human readable code into a form which the machine can understand.

Compiler converts human written commands in to binary forms so that machines can understand them and interpret them. For compilation they first check the programs for syntax errors, available memory required for compilation, and then they start with the process.

Compilers itself are some programmers written in machine understandable language, which have main purpose to decode other commands written in other (General) languages.

Watch out for the latest Weekly Contests | Contest Rules
A Game - Say "Hello"
We are looking for Global Moderator
 
webmaster forum
polas  Offline
*
 
Hacker
Gender: Male
Posts: 1224
Topics: 78
WWW
September 08, 2009, 09:07:46 AM

Compiler converts human written commands in to binary forms so that machines can understand them and interpret them.
Not always, there is nothing to say that a compiler could not convert a higher level language to a lower level one, springing to mind converting some language to C, - this is a very popular option as it presents numerous advantages.

For compilation they first check the programs for syntax errors, available memory required for compilation, and then they start with the process.

Often, but not always Wink - this is known as static analysis, the amount of static analysis performed will depend on the compiler and language itself - for instance a C compiler will probably do less static analysis over memory than a Java one. Another form of analysis is dynamic analysis, this is where code is placed into the target code to detect errors at runtime which can not be done during compilation.

Compilers itself are some programmers written in machine understandable language

Quite interesting is where compilers are written in the language they are compiling (such as javacc, there are many)

Mesham Type Oriented Parallel Programming Language
Skydive in North East England
 
webmaster forum
Admin  Offline
*
 
Hacker
Location: India
Gender: Male
Posts: 1101
Topics: 94
Technical_Talk
WWW
September 08, 2009, 09:27:26 AM

Hey Polas thanks for putting more light on this. I was just talking about general compilers and trying to elaborate definition of compilers.

Watch out for the latest Weekly Contests | Contest Rules
A Game - Say "Hello"
We are looking for Global Moderator
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC


Google visited last this page July 05, 2010, 11:42:34 PM

Valid XHTML 1.0 Transitional     Valid XHTML 1.0 Transitional