This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: explicit template inst. on hpux / optimizer



Hi,

I'm not a C or C++ programmer by any means but...

I have been assigned to support a fairly big project in toxicology data mining
and the sci guys specified egcs on hp.  The application is A++P++.

I have not compiled any usable executables though the libraries I compiled
checked out.

I have been using gnu ld and I used it to compile the latest perl5 and the
executable passed all the regression tests.

So gcc works all around.

This is the ld:
/opt/gcc/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.8.1/ld

I believe that it was given to me in a binary form.  If you want I can
transport this stuff to you if you have access to an ftp site.



--- Markus Werle <markus@lufmech.rwth-aachen.de> wrote:
> Hi!
> 
> In my code example I explicitly instantiate a template which calls template
> functions in its constructor, so these are implicitly
> instantiated.
> Everything works fine on a linuxpc, but the linker fails on hpux.
> Since I have to use hp ld on hpux this may be a linker bug from hp-ux 10.20
> (B.10.20 A 9000/780) but I am not sure,
> so please take a glance at this:
> 
> linuxpc > g++ --version
> egcs-2.91.66
> linuxpc > g++ -c main.C && g++ -c File1.C && g++ -o test main.o File1.o
> linuxpc > ./test
> We trust in God
> 
> Everything above was fine and expected, now:
> 
> hpux > g++ --version
> egcs-2.91.66
> hpux > g++ -c main.C && g++ -c File1.C && g++ -o test main.o File1.o
> /usr/ccs/bin/ld: Unsatisfied symbols:
>    Demo<double>::f(void)(code)
> collect2: ld returned 1 exit status
> 
> 
> Here is the code:
> -----------File1.h--------------
> #ifndef FILE_ONE_H
> #define FILE_ONE_H
> #include <iostream>
> 
> template<class C> class  Demo {
>   C garbage;
> public:  void f(); // I just wanna define it somewhere else };
> 
> #endif
> 
> -----------File1.C--------------
> #include "File1.h"
> 
> template<class C> void Demo<C>::f() {
>   cout << "We trust in God" << endl; }
> 
> // this is a special trick to instantiate recursively:
> // an explicit instantiation of the constructor instantiates
> // implicitly Demo<C>::f()
> template<class C> class Instantiator {
>   Demo<double> D;
> public:
>   Instantiator() { D.f(); }
> };
> 
> // here we go
> template Instantiator<double>;
> 
> ------------main.C--------------
> #include <iostream.h>
> #include "File1.h"
> 
> int main() {
>   Demo<double> D;
> 
>   D.f();
> }
> 
> 
> ========================================
> 
> By the way:
> The example above also fails to link on linux, when using option -O3.
> (not so with -O2 and -O1)
> So implicit instantiation through explicit instantiation
> is gone away when using optimization. :-(
> 
> 
> linuxpc > g++ -c main.C && g++ -c File1.C && g++ -o test main.o File1.o
> /usr/ccs/bin/ld: Unsatisfied symbols:
>    Demo<double>::f(void)(code)
> collect2: ld returned 1 exit status
> 
> adding explicit instantiation is fine, but not what we wanted:
> template void Demo<double>::f(); // class Instantiator obsolete ...
> 
> Any compiler-option to force same behaviour with and without
> optimization welcome. Thanks for Your help.
> 
> Best regards,
> 
> Markus
> 
> 
> 
> 

===
John van Vlaanderen

      #########################################
      #    CXN, Inc. Contact:                 #
      #    john@thinman.com, www.thinman.com  #
      #    1 917 309 7379 (cell, voice mail)  #                   
      #########################################
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]