public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "alexander dot schmitt at wibu dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/26173] New: derived template class with virtual functions implemented in a seperated file does not link Date: Wed, 08 Feb 2006 11:21:00 -0000 [thread overview] Message-ID: <bug-26173-12155@http.gcc.gnu.org/bugzilla/> (raw) The following case can be reproduced with the attached sample. If I have a C++ base class with a virtual function and a derived (template) class and the virtual function is implemented in a own file (-> classb.cpp), the linker does not find the symbol of the function. If the function is implemented inline it will works. The problem seems to be that the object file (classb.o) does not contains the symbol information. The problem seems to be new with gcc 4.0. With gcc 3.3 it works. We have reproduced this with gcc 4.0.1 on Mac OS X and Linux. Using the sample: - unpack attached test.zip - call ./ma.sh in shell terminal (gcc 4.0 envirnment must be set) For me that seems to be a bug because I have not found a compiler switch, etc. to make this working. ================== -> proj.h #include <stdio.h> #include <unistd.h> class A { public: A() { ma = 0; } // A() virtual ~A() { } // A() virtual int Method1() = 0; protected: int ma; }; // A template <typename T> class B { public: B() { mb = 0; } // B() virtual ~B() { } // B() virtual int Method1(); protected: T mb; }; // B ================== -> main.cpp #include "proj.h" int main() { B<short> bs; bs.Method1(); B<int> bi; bi.Method1(); B<long> bl; bl.Method1(); return 0; } // main() ================== -> classb.cpp #include "proj.h" template class B<short>; template class B<int>; template class B<long>; template <typename T> int B<T>::Method1() { printf("pid = %ld\n", (long) getpid()); return 0; } // Method1() ================== -> ma.sh (for Mac OS X) g++ -c -O1 -arch ppc -arch i386 -o main.o main.cpp g++ -c -O1 -arch ppc -arch i386 -o classb.o classb.cpp g++ -o Test1ppc -arch ppc -isysroot /Developer/SDKs/MacOSX10.4u.sdk main.o classb.o -framework Carbon -lstdc++ g++ -o Test1i386 -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk main.o classb.o -framework Carbon -lstdc++ -- Summary: derived template class with virtual functions implemented in a seperated file does not link Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: alexander dot schmitt at wibu dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26173
next reply other threads:[~2006-02-08 11:21 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2006-02-08 11:21 alexander dot schmitt at wibu dot com [this message] 2006-02-08 12:48 ` [Bug c++/26173] " pinskia at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-26173-12155@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).