public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* how to compile and link embedded template class with g++
@ 2005-05-19 20:39 robin
  2005-05-19 21:23 ` Vidyasagara Guntaka
  0 siblings, 1 reply; 3+ messages in thread
From: robin @ 2005-05-19 20:39 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to compile and link embedded template class with g++
  2005-05-19 20:39 how to compile and link embedded template class with g++ robin
@ 2005-05-19 21:23 ` Vidyasagara Guntaka
  2005-05-20  1:52   ` robin
  0 siblings, 1 reply; 3+ messages in thread
From: Vidyasagara Guntaka @ 2005-05-19 21:23 UTC (permalink / raw)
  To: armrobin; +Cc: gcc-help

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
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: how to compile and link embedded template class with g++
  2005-05-19 21:23 ` Vidyasagara Guntaka
@ 2005-05-20  1:52   ` robin
  0 siblings, 0 replies; 3+ messages in thread
From: robin @ 2005-05-20  1:52 UTC (permalink / raw)
  To: vguntaka; +Cc: gcc-help

thanks, Guntaka!

Nurbs++ project put the all template implementation in the header files,
like as vector.h, barray.h ...

discourage me, that I include the header file and explicitly indicating
the libs, error always is here !!!

				Robin

On Thu, 2005-05-19 at 14:22 -0700, Vidyasagara Guntaka wrote:
> 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
> > 
> > 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-05-20  1:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-19 20:39 how to compile and link embedded template class with g++ robin
2005-05-19 21:23 ` Vidyasagara Guntaka
2005-05-20  1:52   ` robin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).