LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-12-2003, 02:27 PM   #1
ksd
Member
 
Registered: Sep 2003
Location: lost in Eastern Kansas,USA
Distribution: FC3,Slackware ,ubuntu
Posts: 130

Rep: Reputation: 15
compiling c,c++ programs


hey does any one know how to compile and run c,c++ programs in linux.i am confident that the gcc compiler is loaded into my system while i was installing linux.i wanna work out on c..some one help me out plz...
 
Old 10-12-2003, 03:24 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
The command to compile your program is
gcc -o executablename filename.c
You can also use the shorter version:
gcc filename.c
(it produces a.out file)
 
Old 10-13-2003, 03:37 AM   #3
ksd
Member
 
Registered: Sep 2003
Location: lost in Eastern Kansas,USA
Distribution: FC3,Slackware ,ubuntu
Posts: 130

Original Poster
Rep: Reputation: 15
hey i did not get it exactly.initially
i will open a new program using vi new1.c
then,i write the code and compile it like this ..

gcc new1.c
then what is a.out?please be more specific.
 
Old 10-13-2003, 03:45 AM   #4
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
a.out is what the output executable file will be called unless you specify a name for it with the -o switch, as in Mara's example.

hw
 
Old 10-13-2003, 04:03 AM   #5
ksd
Member
 
Registered: Sep 2003
Location: lost in Eastern Kansas,USA
Distribution: FC3,Slackware ,ubuntu
Posts: 130

Original Poster
Rep: Reputation: 15
hey every one is being obscure in giving their replies. can you be more clear?i opened the console and
did

vi dhhh.cpp
then with in the vi editor,i typed the code and pressed ctrl+alt+z ,came out and then compiled
gcc -o dh.out dhhh.cpp
when i run the above command, i get a n error saying


Code:
root@dheeraj:~# gcc -o dh.out dhhh.cpp
gcc: dhhh.cpp: No such file or directory
gcc: no input files
root@dheeraj:~#
now what do i do ??
 
Old 10-13-2003, 04:19 AM   #6
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
Quote:
Originally posted by ksd
hey every one is being obscure in giving their replies. can you be more clear?i opened the console and
did

vi dhhh.cpp
then with in the vi editor,i typed the code and pressed ctrl+alt+z ,came out and then compiled
gcc -o dh.out dhhh.cpp
when i run the above command, i get a n error saying


Code:
root@dheeraj:~# gcc -o dh.out dhhh.cpp
gcc: dhhh.cpp: No such file or directory
gcc: no input files
root@dheeraj:~#
now what do i do ??
what does ctrl-alt-z do in vi? i honestly don't have any idea. the way i learned how to save a file in vi is when you're done editing, press the esc key to get into command mode. then type ":" to enter the command, "wq". there's no quotes around the vi commands. then run the gcc command givent to you by mara.

when you want to run the compiled program use the command:
./dh.out

if you're using the command in the quote.
also, btw, get out of root and use a user account.
 
Old 10-13-2003, 05:53 AM   #7
rid00z
LQ Newbie
 
Registered: Sep 2003
Posts: 10

Rep: Reputation: 0
*.cpp is c++ code... so use g++

do this:

g++ XXX.cpp //this compiles the code

./a.out //this is the program produced by the compile

to change the output file

g++ XXX.cpp > newbie

./newbie
 
Old 10-13-2003, 07:22 AM   #8
praveenk
Member
 
Registered: Oct 2003
Location: /india/tn/chennai/vadapalani/hcl/networking
Distribution: Debian GNU/Linux SID, FreeBSD
Posts: 59

Rep: Reputation: 15
I don't have an idea of Ctrl+Alt+Z in Vi. I think that it would suspend the process. Ctrl+Z! So, save your file in vi by using the command :wq and then try compiling it.

My advice to newbies is that go for simple editors like pico, nano, jed intially or spend some time in reading the help for vi or emacs.

If your program is hello.c, then

gcc hello.c
./a.out

(or)

gcc hello.c -o hello
./hello

If your program is a C++ program, hello.cc

g++ hello.cc
./a.out

(or)

g++ hello.cc -o hello
./hello

Last edited by praveenk; 10-13-2003 at 07:25 AM.
 
Old 10-13-2003, 08:59 AM   #9
ksd
Member
 
Registered: Sep 2003
Location: lost in Eastern Kansas,USA
Distribution: FC3,Slackware ,ubuntu
Posts: 130

Original Poster
Rep: Reputation: 15
hey thanx praveenk for your reply.i have already implemented my first c++ program on my slack..
thanx all....btw i am beginning to feel vi is not a very good editor for newbies..so i will better try out ....
some other editors....emacs.....
 
Old 10-13-2003, 09:23 AM   #10
praveenk
Member
 
Registered: Oct 2003
Location: /india/tn/chennai/vadapalani/hcl/networking
Distribution: Debian GNU/Linux SID, FreeBSD
Posts: 59

Rep: Reputation: 15
Hey Emacs is more painful than Vi and also more powerful too. Emacs learning curve is more than that of Vi. My suggestion is that joe, jed, nano, pico are suitable for newbies.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling Programs Faxanadu Linux - Software 3 05-30-2005 02:51 AM
Compiling Programs Thorrn4 Linux - Software 6 03-26-2005 01:25 AM
I need help with compiling my C++ programs. bitessy Programming 3 02-23-2004 07:07 PM
Compiling Programs mike35 Linux - Newbie 2 10-22-2003 10:39 AM
compiling programs disorderly Linux - Newbie 2 10-17-2003 01:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration