Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: [clug-programming] getting started in programming...

From: Mat Kovach <mkovach-clug-programming(at)neolug.org>
Date: Tue Nov 26 2002 - 10:34:38 EST

On Tue, Nov 26, 2002 at 06:11:16AM -0800, Joe Frost wrote: } else. Maybe joe. I name everything joe.

I hope you don't have any daughters!

The original question shows somebody new to UNIX programming (it appears).

It might be wise to surf the web a bit a learn about the UNIX programming enviroment (make, etc) which can be a bit confusing to new people (heck, even long time users can get confused).

The basic problem this person had was that they used gcc (the c compiler) instead of g++ (the gnu c++ compiler).

While he had the correct syntax, he did a few things that warrent a bit of discussion.

In UNIX, you don't have to end an executable (or just about any file) with an extention to make it executable. That is handled by providing the correct file mod bits (chmod u+x allows the user to execute it). gcc/g++ will do this for you.

Do you need help?X

mkovach@neolug:~ > cat test.c
void main()
{
  printf("Hello There\n");
}
mkovach@neolug:~ > gcc -o hello test.c
test.c: In function `main':
test.c:2: warning: return type of `main' is not `int' mkovach@neolug:~ > ./hello
Hello There
mkovach@neolug:~ > ls -l hello
-rwxr-xr-x 1 mkovach users 13319 Nov 26 10:19 hello

The usage of -lm (to include the math library) is not needed as the man c/c++ libraries (glibc) include the functionality of the old libm, so that is not required.

Also, .cc, .c++ or .C is generally the accepted source code extention for C++ programs.

I would change the orginal command to:

g++ -o cc-test test.c

Now, if you still find errors about missing header files it could be possible that you don't have the correct C++ development packages installed.

You also might want to consdier learning how to use make, or create some simple compile, make-exe shell files to save you some typing.

I'll use something like:

Do you need more help?X

kovachme@dev1:/home/kovachme/projects/base> more compile #!/bin/sh
exec gcc -O2 -c ${1+"$@"}

kovachme@dev1:/home/kovachme/projects/base> more make-exe #!/bin/sh
main="$1"; shift
exec gcc -s -o "$main" "$main".o ${1+"$@"}

(whose I idea I stole from somebody else).

This allows me to compile programs and then create executables.

kovachme@techsrv3:/home/kovachme/projects/base> cat >> hello.c << END
> void main()
> {
> printf("hello world\n");
> return;
> }
> END

kovachme@dev1:/home/kovachme/projects/base> ./compile hello.c hello.c: In function `main':
hello.c:2: warning: return type of `main' is not `int' kovachme@dev1:/home/kovachme/projects/base> ./make-exe hello kovachme@dev1:/home/kovachme/projects/base> ./hello hello world

Mat

-*-*-
This message brought to you by the clug-programming mailing list. To unsubscribe email to majordomo@cleveland.lug.net with the body: unsubscribe clug-programming
OTHER CLUG MAILING LISTS:

clug-support	-- For all your linux support needs
clug-announce	-- For all announcements of upcoming CLUG events
And don't forget about our website: http://cleveland.lug.net Received on Tue Nov 26 14:04:10 2002

This archive was generated by hypermail 2.1.8 : Wed Aug 23 2006 - 12:41:05 EDT

Can we help you?X

Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library