This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: how to compile and link embedded template class with g++
- From: Vidyasagara Guntaka <vguntaka at brocade dot com>
- To: armrobin at 21cn dot com
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 19 May 2005 14:22:53 -0700
- Subject: Re: how to compile and link embedded template class with g++
- References: <1116535325.7429.20.camel@tt08.titan>
- Reply-to: vguntaka at brocade dot com
Robin,
This might help you:
Try including the corresponding Template Implementation file instead of
the declaration file. For Example:
Consider the case where one declares MyTemplateClass in
MyTemplateClass.h and the definition is put in MyTemplateClass.cpp. Now
if you want to use the MyTemplateClass, you have to include
MyTemplateClass.cpp NOT MyTemplateClass.h. You have to do this for all
the template based classes. Otherwise there will be undefined symbols.
Regards,
Sagar.
On Fri, 2005-05-20 at 04:42 +0800, robin wrote:
> Hi, all:
>
> I arm using the libnurbs library in my project,
> the libnurbs is a Nurbs spline project,
> http://libnurbs.sourceforge.net
> this project widely use the emdded template class as data type.
>
> I just want to test the libnurbs with my below code:
>
> --------------
> /*
> * file mynurbs.cpp
> */
>
> #include <nurbs++/nurbs.h>
>
> // testing of interpolation and approximation
>
> using namespace PLib;
>
> int main(void)
> {
> int i;
>
> int deg = 3;
> Vector_HPoint3Df P(10); // this is linking error sentenc
>
> printf("Test nurbs++ !\n");
> return 0;
> }
>
> ----------------------
>
> and compile the code with below command:
>
> $ g++ -o mycurve mycurve.cpp
>
> but some error was prompted to me:
>
> -------------------------
>
> /tmp/ccWEpvZI.o(.gnu.linkonce.t._ZN4PLib6VectorINS_9HPoint_nDIfLi3EEEED1Ev+0x16): In function `PLib::Vector<PLib::HPoint_nD<float, (int)3> >::~Vector [in-charge]()':
> : undefined reference to `PLib::BasicArray<PLib::HPoint_nD<float,
> (int)3> >::~BasicArray [not-in-charge]()'
> /tmp/ccWEpvZI.o(.gnu.linkonce.r._ZTVN4PLib6VectorINS_9HPoint_nDIfLi3EEEEE+0x10): undefined reference to `PLib::BasicArray<PLib::HPoint_nD<float, (int)3> >::reset(PLib::HPoint_nD<float, (int)3>)'
> /tmp/ccWEpvZI.o(.gnu.linkonce.t._ZN4PLib6VectorINS_9HPoint_nDIfLi3EEEEC1Ei+0x14): In function `PLib::Vector<PLib::HPoint_nD<float, (int)3> >::Vector[in-charge](int)':
> : undefined reference to `PLib::BasicArray<PLib::HPoint_nD<float,
> (int)3> >::BasicArray[not-in-charge](int)'
> /tmp/ccWEpvZI.o(.gnu.linkonce.t._ZN4PLib6VectorINS_9HPoint_nDIfLi3EEEED0Ev+0x16): In function `PLib::Vector<PLib::HPoint_nD<float, (int)3> >::~Vector [in-charge deleting]()':
> : undefined reference to `PLib::BasicArray<PLib::HPoint_nD<float,
> (int)3> >::~BasicArray [not-in-charge]()'
> collect2: ld returned 1 exit status
>
> --------------
>
> why? what should I do that in order to compiling and linking the
> templated classes with g++?
>
>
> thanks in advanced
> Robin
>
>