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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
10-12-2003, 02:27 PM
|
#1
|
Member
Registered: Sep 2003
Location: lost in Eastern Kansas,USA
Distribution: FC3,Slackware ,ubuntu
Posts: 130
Rep:
|
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...
|
|
|
10-12-2003, 03:24 PM
|
#2
|
Moderator
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696
|
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)
|
|
|
10-13-2003, 03:37 AM
|
#3
|
Member
Registered: Sep 2003
Location: lost in Eastern Kansas,USA
Distribution: FC3,Slackware ,ubuntu
Posts: 130
Original Poster
Rep:
|
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.
|
|
|
10-13-2003, 03:45 AM
|
#4
|
Senior Member
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032
Rep:
|
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
|
|
|
10-13-2003, 04:03 AM
|
#5
|
Member
Registered: Sep 2003
Location: lost in Eastern Kansas,USA
Distribution: FC3,Slackware ,ubuntu
Posts: 130
Original Poster
Rep:
|
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 ??
|
|
|
10-13-2003, 04:19 AM
|
#6
|
Senior Member
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054
Rep:
|
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.
|
|
|
10-13-2003, 05:53 AM
|
#7
|
LQ Newbie
Registered: Sep 2003
Posts: 10
Rep:
|
*.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
|
|
|
10-13-2003, 07:22 AM
|
#8
|
Member
Registered: Oct 2003
Location: /india/tn/chennai/vadapalani/hcl/networking
Distribution: Debian GNU/Linux SID, FreeBSD
Posts: 59
Rep:
|
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.
|
|
|
10-13-2003, 08:59 AM
|
#9
|
Member
Registered: Sep 2003
Location: lost in Eastern Kansas,USA
Distribution: FC3,Slackware ,ubuntu
Posts: 130
Original Poster
Rep:
|
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.....
|
|
|
10-13-2003, 09:23 AM
|
#10
|
Member
Registered: Oct 2003
Location: /india/tn/chennai/vadapalani/hcl/networking
Distribution: Debian GNU/Linux SID, FreeBSD
Posts: 59
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 02:04 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|