POV-Ray : Newsgroups : povray.off-topic : My first C++ program : Re: My first C++ program Server Time
1 Oct 2024 03:13:01 EDT (-0400)
  Re: My first C++ program  
From: Warp
Date: 20 Sep 2008 06:22:34
Message: <48d4cee9@news.povray.org>
Orchid XP v8 <voi### [at] devnull> wrote:
> > g++ -Wall -Wextra -pedantic -ansi -O3 yourprogram.cc

> Actually, when I want to compile something, I usually just say "make 
> foo". Otherwise GCC insists on naming it "a.out", which is very irritating.

  If you don't specify an executable name, how can gcc guess what is it
that you want? Note that you can write something like:

g++ file1.cc file2.cc file3.cc

  Which one of those is the one you want the executable named after?
Or maybe you don't want the executable to be named anything those.

  AFAIK all compilers require you to specify an executable name. It's
just that in most compilers this happens when you are creating a project.
However, gcc is command-line oriented and doesn't have projects. It doesn't
need to support projects because 'make' is the de-facto project software
in unix systems, and there's no need for gcc to step onto its toes.

  Of course the way to tell gcc the name of the executable is to tell it
to it with the -o parameter.

> I'm rather surprised that forgetting to return anything at all isn't 
> considered a non-maskable error, but anyway...

  C++ inherits many things from C, good and bad.

> >   Learn to use makefiles too. You can use the attached generic makefile
> > to automatically build your program. (You'll probably need gnu make.)
> > 
> >   (Note that if you add, remove or change any #include line in your
> > program, except those which include standard libraries, you'll have to
> > delete the .dep file before running make.)

> So there *is* a way to automate dependency analysis?

  The -MM option of gcc (which I use in that generic makefile I attached)
auto-generates makefile dependencies for all the specified source
files. Makefiles themselves (at least with gnu make) are so versatile
that this can be used to completely automatize dependency building.

  Well, *almost* completely. 'make' has no way of knowing if you have
changed some #include line in some source code file, which would change
the dependencies. Of course it would be perfectly possible to make it
build the dependency file every time you run 'make', but I usually don't
want that, because the "g++ -MM" command often takes a few seconds to run,
which can be irritating, and dependencies change rarely.

  If you want it to run the "g++ -MM" every time, you can do it like in
the attached Makefile.

> This whole concept of having to manually write makefiles and manually 
> write header files and so forth just seems tedious and error-prone.

  You don't need to manually write makefiles. Just use a generic one.


Post a reply to this message


Attachments:
Download 'Makefile.txt' (1 KB)

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.