PDA

View Full Version : how to compile a c program



ankitguptag18
March 20th, 2008, 09:08 AM
i have created da most comon "Hello World" c program but how do i compile da program.....i have g++ installed

first.c

#include <stdio.h>
void main()
{
printf("Hello World");
getch();
}

lnostdal
March 20th, 2008, 09:26 AM
the faq leads you to http://ubuntuforums.org/showthread.php?t=689635

Kadrus
March 20th, 2008, 09:31 AM
First of all there is an error in the code..
let's consider this:


#include<stdio.h>
int main()
{
printf("Hello World");
getchar();
return 0;
}

Save the file ex.c
Alright..I am assuming that you have installed gcc...the compiler of C
if you haven't type in terminal


sudo apt-get install build-essential
That will install the compilers..
when it's installed type in terminal

gcc ex.c
then type

./a.out
This should do it
good luck:)

ankitguptag18
March 20th, 2008, 09:43 AM
do we have a compiler n editor......like borland....

twright
March 20th, 2008, 10:19 AM
you can try eclipse and it's C++ plugin

lnostdal
March 20th, 2008, 10:24 AM
yeah, some like an IDE like kdevelop (similar to borland) .. others prefer an environment where everything is loosely coupled together

but, if you are _serious_(#1) about development (on linux) you will learn how each part(#2) works in isolation, and you will learn how to hook things together yourself .. when you know this you can either:

* keep using an IDE

* create your own IDE by "connecting the parts" and adding event-hooks or short-cut keys to them

..regardless of what you do you will then understand how things work, and where, why and how things fail when they do

(something about IDEs and development environments should be added to the FAQ so we can end these repeating discussions/questions for good .. )


#1: if someone want to discuss the part about "seriousness" .. just, don't .. you are wasting your time as i am 100% correct anyway(!) .. feel free to ask questions, though; don't question what i've said here as i do not care to discuss it with you .. (yes, i'm tired of these threads/discussions)

#2: the compiler, the linker, the run-time linker/library loader, the debugger .. etc.

MONODA
March 20th, 2008, 10:26 AM
check out geany it is a great IDE which alows you to compile your program. Its also a nice lightweight text editor.

k2t0f12d
March 20th, 2008, 10:28 AM
do we have a compiler n editor......like borland....

anjuta
kdevelop
geany
eclipse
netbeans

Kadrus
March 20th, 2008, 11:08 AM
There is a Gedit which is a great IDE in my mind...check the stickies..for more info..because each person is going to give you a different opinion on what to use..

Wybiral
March 20th, 2008, 11:15 AM
There is a Gedit which is a great IDE in my mind...check the stickies..for more info..because each person is going to give you a different opinion on what to use..

Gedit is more of a "programmers text editor" than it is an IDE. But when you use the embedded terminal plugin, it pretty nicely for developing in most languages.

ruy_lopez
March 20th, 2008, 12:11 PM
Vim + gcc + make

It might not be very integrated. But it's still a development environment.