[Gc] Beginner's questions

David Jones dej at inode.org
Tue Apr 6 11:41:27 PDT 2004


On April 6, 2004 07:39 am, Atip Asvanund wrote:

> 1) The instruction said to include the header file, and link to the
> library file. I was wondering if I am doing it correctly in my makefile:
>
> -bash-2.05b$ more makefile
> queries:        queries.cpp queries.h /new/usr2/xxx/gc/include/gc.h
>                 g++ -g -o3 queries.cpp /new/usr2/xxx/gc/lib/libgc.a -o
> queries
>
> I also include the gc.h file in my source.

You must include the gc.h in your source.  You need not include it on the g++ 
command line.

You must ensure that g++ can see the directory in which gc.h is stored.  If 
this is not already the case on Linux, then you must use a -I directive on 
the command line to indicate the directory in which gc.h resides.  In your 
case, you will need "-I/new/usr2/xxx/gc/include" on the compiler command 
line.

> 2) The instruction said specifically to run "make c++" after a regular
> make. I get the following error message, while the regular make and make
> install works. I am using c++, so will this cause a problem?
>
> -bash-2.05b$ make c++
> make: *** No rule to make target `c++'.  Stop.

This step is required when building the collector itself.  It is not required 
when building your program.

If you are using C++, then you should include gc_cpp.h for a nicer interface 
to the collector.

> 3) I am using STL for most of my complex datasets. Does STL work at all
> with Boehm? If it does, does it work automatically, or do I need to
> specify some special options. What will happen if I use the following
> defines:

For STL, you must use special allocators.  Basically, include "gc_allocator.h" 
into your program, which defines the "gc_allocator" class.  You then need to 
specify this allocator when you create your containers, e.g.:

typedef std::vector<Foo*, gc_allocator<Foo*> > FooVector;

FooVector v;

> 4) In C++ do I include gc.h or do I use a different file?

See above.

> 5) Is there a gentler introduction to Boehm with examples that I can use?

The documentation included with the collector is more than adequate.  Your 
problems seem to stem from inexperience with the standard compiler options 
for g++ as well as proper usage of allocators for STL containers.  You need 
to master the basics before you go on to complex things.

For more background on g++ options, refer to any book on Unix/Linux C/C++ 
software development.  You should pay attention to the concepts surrounding 
separate compilation, as that will apply as your project grows more complex.

For more background on custom STL allocators, refer to Josuttis, "The C++ 
Standard Library: A Tutorial and Reference", ISBN 0-201-37926-0.



More information about the Gc mailing list