I'm trying to do a program in c++, but when I try to compile, it doesn't works. The code is attached to this message. Just know that I have a template class (SuffixTree) used in the main func. The problem seems to be that the method of this class aren't instanciated like they have to be. Since it doesn't seems to me I made a mistake, I assume this is a gcc bug. But perhaps am I wrong. If so, just tell me (in fact I'm new in using templates). Also note I already try to force the instanciation by adding the line : template class SuffixTree<int>; in some file, but all it does was worst than what I already have. Reproducible: Always Steps to Reproduce: 1.compile the different files (works just fine) 2.Try to link them in order to create the executable 3.it fails Actual Results: reports these test_suffix_node.o(.text+0xc2): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::insert(int&, char const*)' test_suffix_node.o(.text+0xcd): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::print_tree()' test_suffix_node.o(.text+0x11b): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::key_exist(char const*)' test_suffix_node.o(.text+0x1ba): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::print_tree()' collect2: ld a retourn
I'm trying to do a program in c++, but when I try to compile, it doesn't works. The code is attached to this message. Just know that I have a template class (SuffixTree) used in the main func. The problem seems to be that the method of this class aren't instanciated like they have to be. Since it doesn't seems to me I made a mistake, I assume this is a gcc bug. But perhaps am I wrong. If so, just tell me (in fact I'm new in using templates). Also note I already try to force the instanciation by adding the line : template class SuffixTree<int>; in some file, but all it does was worst than what I already have. Reproducible: Always Steps to Reproduce: 1.compile the different files (works just fine) 2.Try to link them in order to create the executable 3.it fails Actual Results: reports these test_suffix_node.o(.text+0xc2): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::insert(int&, char const*)' test_suffix_node.o(.text+0xcd): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::print_tree()' test_suffix_node.o(.text+0x11b): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::key_exist(char const*)' test_suffix_node.o(.text+0x1ba): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::print_tree()' collect2: ld a retourné 1 code d'état d'exécution Expected Results: create the executable Portage 2.0.51.19 (default-linux/x86/2005.0, gcc-3.3.5, glibc-2.3.4.20041102-r1, 2.6.11-gentoo-r4 i686) ================================================================= System uname: 2.6.11-gentoo-r4 i686 AMD Athlon(tm) XP 2000+ Gentoo Base System version 1.4.16 Python: dev-lang/python-2.3.4-r1 [2.3.4 (#1, Apr 5 2005, 17:51:08)] dev-lang/python: 2.3.4-r1 sys-apps/sandbox: [Not Present] sys-devel/autoconf: 2.13, 2.59-r6 sys-devel/automake: 1.5, 1.8.5-r3, 1.7.9-r1, 1.6.3, 1.4_p6, 1.9.4 sys-devel/binutils: 2.15.92.0.2-r1 sys-devel/libtool: 1.5.10-r4 virtual/os-headers: 2.6.8.1-r2 ACCEPT_KEYWORDS="x86" AUTOCLEAN="yes" CFLAGS="-O3 -march=athlon-xp -fomit-frame-pointer -pipe" CHOST="i686-pc-linux-gnu" CONFIG_PROTECT="/etc /usr/kde/2/share/config /usr/kde/3/share/config /usr/lib/X11/xkb /usr/share/config /usr/share/texmf/dvipdfm/config/ /usr/share/texmf/dvips/config/ /usr/share/texmf/tex/generic/config/ /usr/share/texmf/tex/platex/config/ /usr/share/texmf/xdvi/ /var/qmail/control" CONFIG_PROTECT_MASK="/etc/gconf /etc/terminfo /etc/env.d" CXXFLAGS="-O3 -march=athlon-xp -fomit-frame-pointer -pipe" DISTDIR="/usr/portage/distfiles" FEATURES="autoaddcvs autoconfig ccache distlocks sandbox sfperms strict" GENTOO_MIRRORS="http://mirror.datapipe.net/gentoo http://mirror.datapipe.net/gentoo http://gentoo.inode.at/" LANG="fr_FR@euro" LC_ALL="fr_FR@euro" LINGUAS="fr fr_FR" MAKEOPTS="-j2" PKGDIR="/usr/portage/packages" PORTAGE_TMPDIR="/var/tmp" PORTDIR="/usr/portage" SYNC="rsync://rsync.gentoo.org/gentoo-portage" USE="x86 3dnow X Xaw3d aalib acl acpi adns alsa apm arts audiofile avi berkdb bitmap-fonts bonobo cdr crypt cscope cups curl dga directfb divx4linux doc dvd dvdr emboss encode esd evo fam fastcgi fbcon flac foomaticdb fortran gb gd gdbm gif gnome gphoto2 gpm gstreamer gtk gtk2 gtkhtml guile imagemagick imap imlib innodb ipv6 java jikes joystick jpeg junit kerberos krb4 ldap libg++ libwww mad mikmod mmx motif mozilla mp3 mpeg msn ncurses nls nocd ogg oggvorbis opengl oss pam pdf pdflib perl png python qt quicktime readline samba scanner sdl slang spell sse ssl svga svgalib szip tcltk tcpd tetex tiff truetype truetype-fonts type1-fonts unicode usb videos vorbis wmf wxwindows xine xml xml2 xmms xv xvid zlib video_cards_radeon linguas_fr linguas_fr_FR userland_GNU kernel_linux elibc_glibc" Unset: ASFLAGS, CBUILD, CTARGET, LDFLAGS, PORTDIR_OVERLAY
Created attachment 61350 [details] sources who causes the problem
fails to even compile for me: suffix_node.cc: In member function `bool cpl::internals::SuffixNode<T>::key_exist(const char*)': suffix_node.cc:89: warning: there are no arguments to `get_subnode' that depend on a template parameter, so a declaration of `get_subnode' must be available suffix_node.cc: In member function `cpl::internals::SuffixNode<T>& cpl::internals::SuffixNode<T>::insert(T&, const char*)': suffix_node.cc:123: warning: there are no arguments to `get_subnode' that depend on a template parameter, so a declaration of `get_subnode' must be available suffix_node.cc:127: error: `subNodes' undeclared (first use this function) suffix_node.cc:127: error: (Each undeclared identifier is reported only once for each function it appears in.)
Are you using gcc3.4 series? if so, you need to add this-> before some declaration (those who causes problems). I tested that today, and once you've done it... same result as with gcc3.3.5: problem when linking. If you want, I can send you the corrected sources.
I think it was closed a little too fast....
posted updated sources that dont bomb/dump warnings with gcc-3.4
Created attachment 61715 [details] sources showing the problem with gcc3.4.3 with these files, I get this: test_suffix_node.o(.text+0x1bd): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::insert(int&, char const*)' test_suffix_node.o(.text+0x1c8): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::print_tree()' test_suffix_node.o(.text+0x215): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::key_exist(char const*)' test_suffix_node.o(.text+0x2b4): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::print_tree()' test_suffix_node.o(.gnu.linkonce.r._ZTVN3cpl9internals10SuffixNodeIiEE+0x8): undefined reference to `cpl::internals::SuffixNode<int>::~SuffixNode()' test_suffix_node.o(.gnu.linkonce.r._ZTVN3cpl9internals10SuffixNodeIiEE+0xc): undefined reference to `cpl::internals::SuffixNode<int>::~SuffixNode()' test_suffix_node.o(.gnu.linkonce.r._ZTVN3cpl9internals10SuffixTreeIiEE+0x8): undefined reference to `cpl::internals::SuffixTree<int>::~SuffixTree()' test_suffix_node.o(.gnu.linkonce.r._ZTVN3cpl9internals10SuffixTreeIiEE+0xc): undefined reference to `cpl::internals::SuffixTree<int>::~SuffixTree()' collect2: ld a retourn
Created attachment 61715 [details] sources showing the problem with gcc3.4.3 with these files, I get this: test_suffix_node.o(.text+0x1bd): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::insert(int&, char const*)' test_suffix_node.o(.text+0x1c8): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::print_tree()' test_suffix_node.o(.text+0x215): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::key_exist(char const*)' test_suffix_node.o(.text+0x2b4): In function `main': : undefined reference to `cpl::internals::SuffixTree<int>::print_tree()' test_suffix_node.o(.gnu.linkonce.r._ZTVN3cpl9internals10SuffixNodeIiEE+0x8): undefined reference to `cpl::internals::SuffixNode<int>::~SuffixNode()' test_suffix_node.o(.gnu.linkonce.r._ZTVN3cpl9internals10SuffixNodeIiEE+0xc): undefined reference to `cpl::internals::SuffixNode<int>::~SuffixNode()' test_suffix_node.o(.gnu.linkonce.r._ZTVN3cpl9internals10SuffixTreeIiEE+0x8): undefined reference to `cpl::internals::SuffixTree<int>::~SuffixTree()' test_suffix_node.o(.gnu.linkonce.r._ZTVN3cpl9internals10SuffixTreeIiEE+0xc): undefined reference to `cpl::internals::SuffixTree<int>::~SuffixTree()' collect2: ld a retourné 1 code d'état d'exécution
that version fails for gcc-3.3.[56] gcc-3.4.[34] and gcc-4.0.0 also tested with binutils-2.15 / 2.15.92.0.2 / 2.16 / 2.16.90.0.3 you should file a bug in the gcc bugzilla: http://gcc.gnu.org/bugzilla/ they'll be able to properly help you
I've posted it on the gcc bugzilla, (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22161) seems it comes from me... Sorry for the disagrement.
np see how they were able to give you such a fast answer ? :)