This is the mail archive of the gcc-bugs@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]

templated functions



This may be redundant, as I think I've seen related items in the archives, but
I thought I'd send it in anyway.

I get a link error with templated functions:

---------------<snip t.cpp>------------------
#include <stdio.h>
#include <typeinfo>
 
template <class _Ty>
inline const char * const
TypeName()
{
    return typeid(_Ty).name();
}

int
main(int argc, char* argv[])
{
    printf("%s\n", TypeName<int>());
}
-----------------<snip>----------------------

mlm@jupiter:~$ download/bin/g++ -v -o t t.cpp
Reading specs from /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/specs
gcc version egcs-2.90.12 971008 (gcc2-970802 experimental)
 /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=90 -Dsun -Dsparc -Dunix -D__svr4__ -D__SVR4 -D__GCC_NEW_VARARGS__ -D__sun__ -D__sparc__ -D__unix__ -D__svr4__ -D__SVR4 -D__GCC_NEW_VARARGS__ -D__sun -D__sparc -D__unix -Asystem(unix) -Asystem(svr4) -Acpu(sparc) -Amachine(sparc) -D__EXCEPTIONS t.cpp /var/tmp/cca003gA.ii
GNU CPP version egcs-2.90.12 971008 (gcc2-970802 experimental) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /home/mlm/download/include/g++
 /usr/local/include
 /home/mlm/download/sparc-sun-solaris2.5.1/include
 /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/include
 /usr/include
End of search list.
 /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/cc1plus /var/tmp/cca003gA.ii -quiet -dumpbase t.cc -version -o /var/tmp/cca003gA.s
GNU C++ version egcs-2.90.12 971008 (gcc2-970802 experimental) (sparc-sun-solaris2.5.1) compiled by GNU C version egcs-2.90.10 970924 (gcc2-970802 experimental).
 /usr/ccs/bin/as -V -Qy -s -o /var/tmp/cca003gA1.o /var/tmp/cca003gA.s
/usr/ccs/bin/as: SC4.2 dev 30 Nov 1995
 /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/ld -V -Y P,/usr/ccs/lib:/usr/lib -Qy -o t /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/crt1.o /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/crti.o /usr/ccs/lib/values-Xa.o /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/crtbegin.o -L/home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12 -L/home/mlm/download/sparc-sun-solaris2.5.1/lib -L/usr/ccs/bin -L/usr/ccs/lib -L/home/mlm/download/lib /var/tmp/cca003gA1.o -lstdc++ -lm -lgcc -lc -lgcc /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/crtend.o /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/crtn.o
ld: Software Generation Utilities (SGU) SunOS/ELF (LK-2.0 (S/I) - versioning)
Undefined                       first referenced
 symbol                             in file
TypeName                            /var/tmp/cca003gA1.o
ld: fatal: Symbol referencing errors. No output written to t
collect2: ld returned 1 exit status
mlm@jupiter:~$ download/bin/g++ -v -c t.cpp
Reading specs from /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/specs
gcc version egcs-2.90.12 971008 (gcc2-970802 experimental)
 /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=90 -Dsun -Dsparc -Dunix -D__svr4__ -D__SVR4 -D__GCC_NEW_VARARGS__ -D__sun__ -D__sparc__ -D__unix__ -D__svr4__ -D__SVR4 -D__GCC_NEW_VARARGS__ -D__sun -D__sparc -D__unix -Asystem(unix) -Asystem(svr4) -Acpu(sparc) -Amachine(sparc) -D__EXCEPTIONS t.cpp /var/tmp/cca003zs.ii
GNU CPP version egcs-2.90.12 971008 (gcc2-970802 experimental) (sparc)
#include "..." search starts here:
#include <...> search starts here:
 /home/mlm/download/include/g++
 /usr/local/include
 /home/mlm/download/sparc-sun-solaris2.5.1/include
 /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/include
 /usr/include
End of search list.
 /home/mlm/download/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.12/cc1plus /var/tmp/cca003zs.ii -quiet -dumpbase t.cc -version -o /var/tmp/cca003zs.s
GNU C++ version egcs-2.90.12 971008 (gcc2-970802 experimental) (sparc-sun-solaris2.5.1) compiled by GNU C version egcs-2.90.10 970924 (gcc2-970802 experimental).
 /usr/ccs/bin/as -V -Qy -s -o t.o /var/tmp/cca003zs.s
/usr/ccs/bin/as: SC4.2 dev 30 Nov 1995
mlm@jupiter:~$ nm t.o
         U TypeName
00000000 ? __FRAME_BEGIN__
00000004 C __eh_cleanup
00000004 C __eh_in_catch
00000004 C __eh_pc
00000004 C __eh_type
00000004 C __eh_value
         U __throw
00000000 t gcc2_compiled.
00000000 T main
         U printf
--------------------------------------------------------------

After checking, it doesn't matter whether it's inline or not -- it's
undefined whether or not it's inline.

Mitch

-- 
------------------------------
Law of programming #99: If you can't get your work done in the first 24 hours,
work nights.
Rules of life #109: The more crap you put up with, the more crap you are
going to get.
Rules of life #110:  Eat one live toad the first thing in the morning and
nothing worse will happen to you the rest of the day.


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