Programming, website development forum Get latest updates by RSS Follow TechnicalTalk on Twitter Follow TechnicalTalk on Facebook 
HomeSearchRecent PostsLoginRegisterContact Us

Username  
Password    
  Forgot your password?  

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
Activity
0%
 
New Poster
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
Activity
33.33%
 
Code Guru
Gender: Male
Posts: 1399
Topics: 85
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, Free online technical support
 
webmaster forum
Admin  Offline
*
 
Code Guru
Location: India
Gender: Male
Posts: 1387
Topics: 105
NaviBuster NaviBuster
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.
 
webmaster forum
polas  Offline
Activity
33.33%
 
Code Guru
Gender: Male
Posts: 1399
Topics: 85
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, Free online technical support
 
webmaster forum
Admin  Offline
*
 
Code Guru
Location: India
Gender: Male
Posts: 1387
Topics: 105
NaviBuster NaviBuster
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.
 
webmaster forum
mallory  Offline
Activity
40%
 
New Coder
Posts: 39
Topics: 7
June 16, 2011, 09:06:21 AM

1. install eclipse (not necessary for compiling)
probably you can find it from your package manager if there isn’t
use this link: hxxp: www. eclipse. org
for pardus open pisi search for eclipse and install it ( 3. 3)

2.  install CDT plugin for eclipse
open eclipse help -> software updates -> avilable softwares -> add site
for eclipse 3. 4 add this:

hxxp: download. eclipse. org/tools/cdt/releases/ganymede

for eclipse 3. 3 add this:

hxxp: download. eclipse. org/tools/cdt/releases/europa

check it and click install

you have eclipse CDT to write your c and c++ codes
now you need gcc to compile it

3.  install gcc
find gcc from your package manager.
for pardus write this to console
sudo pisi it gcc

4.  first simple
i opened a new c++ project from eclipse, created new source file, writed my code and saved.  when i am trying to make file,
I received this message “(Exec error:Cannot run make)” .

(solution: install make from your package manager. For pardus write this sudo pisi it make. )

after that i tried it on console with giving this command

(for c++ codes)

    g++ example. cpp

(for c codes)

    gcc example. c

however, i received “iostream. h: No such file or directory gcc”
solution: delete . h just write <iostream> also write g++ for *. cpp files

after i installed make, i was able to compile it from console and eclipse.

if you want to see your code’s output:

    g++ example. cpp

it makes a compiled file named example in your folder

to run it just write

    . /example

i hope , help you.

« Last Edit: July 16, 2011, 09:38:20 AM by Admin »

online email marketing | web designers in chennai
 
webmaster forum
Activity
0%
 
New Poster
Posts: 5
Topics: 0
WWW
July 02, 2011, 05:15:54 AM

There are plenty of c and c++ compiler under unix based operating system, but the most famous one should be GNU gcc compiler.  A well known open source kernel Linux is compiled by gcc as well.
 
webmaster forum
kellylsn  Offline
Activity
0%
 
Professional Coder
Posts: 229
Topics: 7
July 22, 2011, 01:00:29 AM

Thanks for this posting, I am now trying to know that how to compile c in linux.

Payday Loan
Online Easy Loans
 
webmaster forum
Activity
0%
 
New Poster
Posts: 5
Topics: 0
July 29, 2011, 09:43:27 AM

linux helping in runing such codes has been quite helpful
 
webmaster forum
netshet  Offline
Activity
0%
 
Regular Coder
Posts: 73
Topics: 2
WWW
August 03, 2011, 02:51:21 AM

i'm not smart with computers.  I know vb and that's it.  I switched over to linux here with SuSE 8. 2.  I'm just trying the simple hello world application.  Saving my file with the . cc extension.

to compile, i'm running Konsole, then typing gcc -o outputfile test. cc

i've tried outputfile. exe, many other things.  I've also tried compiling with the following:
c++ -o outputfile test. cc

It creates the file, but when I click on it or when I type outputfile in the Konsole mode, it says bash: command not found.  which is the same thing I get when i type asdf or qperiuqeruqpei for that matter.

Thanks for the help everyone.



hair transplant
 
webmaster forum
dianna  Offline
Activity
0%
 
Regular Coder
Posts: 88
Topics: 10
WWW
August 05, 2011, 07:12:24 PM

Till a few years back, it was really difficult to obtain a free version of a compiler to run on ones machine to learn C or C++. And one had to resort to using a commercial compiler either by paying money and buying a licence or using a pirated copy of the same. I still remember, till a couple of years back, Borland C was considered to be the best compiler in the market for windows platform but later Microsoft's Visual-C usurped it to take the most popular position. Then GNU/Linux got wider acceptance and the rest as they say is history. Most GNU/Linux distributions ship with the gcc suite of compilers. GCC stands for GNU Compiler Collection. And it contains compilers for various languages such as C,C++,Java and so on. It is one of the most efficient free implementation of a compiler one can hope to get ones hands on and is available for multiple platforms and OSes including Windows.

Here I will list the basic steps needed to compile a C / C++ program using GCC. The first thing to do is find what version of gcc is installed on ones computer

Pakistan's Local Search engine
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.15 | SMF © 2011, Simple Machines


Google visited last this page February 03, 2012, 12:26:30 AM