And now for some programming...

Ron Peterson rpeterson at yellowbank.com
Sun Jan 2 13:01:34 EST 2000



> How do I run my 'Hello World' C or C++ program using RH Linux? I can't
> seem to locate the words 'how to compile and run' anywhere in the
> documentation.

I see you've gotton a couple of responses.  Here's a little more info
you may or may not find helpful.

You can compile without leaving emacs.  In emacs, type 'ESC-x compile'
(ignore quotes, I'm just using them to set the command sequence off from
my text).  This is probably configured to run the 'make' command with
whatever default arguments have been configured.  You can edit this line
as needed to perform your compilation.  Perhaps 'g++ -o test test.cc',
for example.

Let's say test.cc depends on ybrandom.cc (i.e. - test.cc says #include
"ybrandom.h").  You can compile both files together, like 'g++ -o test
test.cc ybrandom.cc'.  Or if you're done with ybrandom and don't want to
compile it over and over, make an object file of it by typing 'g++ -c
ybrandom.cc'.  This will create a file called ybrandom.o.  You can then
compile test.cc by typing 'g++ -o test test.cc ybrandom.o'.

Someone also mentioned makefiles.  Below is a very simple makefile which
basically does the same thing as above.

test: test.cc ybrandom.o
	g++ -o test test.cc ybrandom.o
ybrandom.o: ybrandom.cc ybrandom.h
	g++ -c ybrandom.cc
clean:
	rm *.o *~

The unindented lines describe dependancies.  The indented lines (use
tabs!) say what to do.  So if you 'make clean', for example, you will
remove your object files and backup files.

Of course, after you finished compiling, you want to run your program to
see how it works.  You still don't have to leave emacs.  Just type
'ESC-x shell' to open a command shell buffer.  This is handy, because
your output is also part of the shell buffer.  Just beware that normal
command shell escape sequences may work a little differently.  E.G. - if
you want to cancel your program (mine always seem to end up in infinite
loops) you need to type 'Ctrl-C Ctrl-C'.  I.E. - try typing 'Ctrl-C'
then whatever.

I highly recommend "Programming with GNU Software", published by
O'Reilly (www.oreilly.com).  This is one of the friendliest books about
programming tools I have ever read.  It covers all the bases while doing
an exceptional job of remaining very readable.  Not too long, not too
short.

Of course there are all kinds of tools, tips, techniques etc. to make
you a more efficient programmer.  Just don't let efficiency get in the
way of actually getting something done, if you know what I mean.  You
don't have to understand all the intricacies of 'make' to write a nice
program.

Good luck and have fun.

Ron Peterson
rpeterson at yellowbank.com (home)
rpeterson at wallacefloyd.com (work)
-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).



More information about the Discuss mailing list