We're wandering OT here, but I hope this is useful to others dealing
with JNI/C++ integration...
Paul Beardsley wrote:
>
> That looks like the problem - I wasn't including the
> templated source at the end of the .h file.
>
> It raises
> a question for me though - for my template classes,
> I previously had a MyFile.H file (with no included source
> at the end) and a MyFile.C file which included MyFile.H
> at the start and then had the source code for the methods.
Templates are one of the ugliest areas of C++, because they put the
compiler and/or linker into the business of generating original code.
Different environments have handled that in different ways, some of them
incredibly ugly. But it's improved in recent years.
>
> I would then compile MyFile.C as though it were
> any other source file, and link together object files
> for template and non-template classes to make an executable.
> I was working on SGI IRIX and the SGI prelinker
> took care of all the required template
> instantiations when making the executable.
>
> But if MyFile.H includes MyFile.C, this seems to require a
> different approach. Do I still compile MyFile.C as
> a stand-alone file at some stage? Or how do things
> work when the source is included in the header file?
> (I'm trying to understand what my Makefile should look
> like).
No need to compile MyFile.C on its own. When you compile sources that
include MyFile.h, the compiler generates whatever specializations it
needs from the sources it got from the header files. That is, once
things are fixed to provide sources in the header files :-).
> Also is this inclusion of the template source in
> the header file something that is specifically
> need for g++, or is it something that's used generally?
I believe this is expected behavior with C++ compilers that claim to be
ANSI-compliant.
Nathan
> Thanks again,
> Paul.
>
> Nathan Meyers writes:
> >
> > You answered my point of curiosity about where the reference was coming
> > from... it's one of your templated classes referenced from within your
> > code. The only thing that springs to mind is to ask whether you're
> > following the conventions for supplying templated source code. It needs
> > to come from the .h file in which the declarations are made -- a common
> > technique is to include a nearby source file. You can see an example in
> > /usr/include/g++-2/std/bastring.h, which declares the classes, and
> > includes (at the end) bastring.cc which provides all of the templated
> > source.
> >
> > ...
> >
> > Nathan
> >
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]