[Bug c++/51812] New: Virtual public inheritance leads to "undefined reference" in header files.

bredelin at ucla dot edu gcc-bugzilla@gcc.gnu.org
Tue Jan 10 14:32:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51812

             Bug #: 51812
           Summary: Virtual public inheritance leads to "undefined
                    reference" in header files.
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: bredelin@ucla.edu


Created attachment 26292
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26292
The c++ file that has linker errors.

Hi,

Using gcc 4.7 causes new linker errors that are not present in e.g. 4.5, 4.6,
or clang.  These linker errors make it impossible to use header files that do
not fully define some classes entirely in the header file.  

The errors look like:

% g++-4.7 all5.C 

/tmp/ccfEMWL0.o: In function `Object::print() const':
all5.C:(.text._ZNK6Object5printEv[_ZNK6Object5printEv]+0x58): undefined
reference to `demangle(std::string const&)'


/tmp/ccfEMWL0.o: In function `alphabet::compare(Object const&) const':
all5.C:(.text._ZNK8alphabet7compareERK6Object[_ZNK8alphabet7compareERK6Object]+0x81):
undefined reference to `typeinfo for alphabet'
all5.C:(.text._ZNK8alphabet7compareERK6Object[_ZNK8alphabet7compareERK6Object]+0xa5):
undefined reference to `operator==(alphabet const&, alphabet const&)'


/tmp/ccfEMWL0.o: In function `alphabet::~alphabet()':
all5.C:(.text._ZN8alphabetD1Ev[_ZN8alphabetD1Ev]+0xe): undefined reference to
`vtable for alphabet'
all5.C:(.text._ZN8alphabetD1Ev[_ZN8alphabetD1Ev]+0x26): undefined reference to
`vtable for alphabet'


/tmp/ccfEMWL0.o: In function `Triplets::Triplets(Triplets const&)':
all5.C:(.text._ZN8TripletsC1ERKS_[_ZN8TripletsC1ERKS_]+0x3d): undefined
reference to `VTT for Triplets'
all5.C:(.text._ZN8TripletsC1ERKS_[_ZN8TripletsC1ERKS_]+0x51): undefined
reference to `vtable for Triplets'
all5.C:(.text._ZN8TripletsC1ERKS_[_ZN8TripletsC1ERKS_]+0x69): undefined
reference to `vtable for Triplets'
/tmp/ccfEMWL0.o:(.rodata._ZTV18AminoAcidsWithStop[_ZTV18AminoAcidsWithStop]+0x48):
undefined reference to `alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTV18AminoAcidsWithStop[_ZTV18AminoAcidsWithStop]+0x60):
undefined reference to `alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTV18AminoAcidsWithStop[_ZTV18AminoAcidsWithStop]+0x70):
undefined reference to
`alphabet::get_frequencies_from_counts(std::valarray<double> const&, double)
const'
/tmp/ccfEMWL0.o:(.rodata._ZTC18AminoAcidsWithStop0_10AminoAcids[_ZTV18AminoAcidsWithStop]+0x48):
undefined reference to `alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTC18AminoAcidsWithStop0_10AminoAcids[_ZTV18AminoAcidsWithStop]+0x60):
undefined reference to `alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTC18AminoAcidsWithStop0_10AminoAcids[_ZTV18AminoAcidsWithStop]+0x70):
undefined reference to
`alphabet::get_frequencies_from_counts(std::valarray<double> const&, double)
const'
/tmp/ccfEMWL0.o:(.rodata._ZTC18AminoAcidsWithStop0_8alphabet[_ZTV18AminoAcidsWithStop]+0x30):
undefined reference to `typeinfo for alphabet'
/tmp/ccfEMWL0.o:(.rodata._ZTC18AminoAcidsWithStop0_8alphabet[_ZTV18AminoAcidsWithStop]+0x48):
undefined reference to `alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTC18AminoAcidsWithStop0_8alphabet[_ZTV18AminoAcidsWithStop]+0x60):
undefined reference to `alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTC18AminoAcidsWithStop0_8alphabet[_ZTV18AminoAcidsWithStop]+0x70):
undefined reference to
`alphabet::get_frequencies_from_counts(std::valarray<double> const&, double)
const'
/tmp/ccfEMWL0.o:(.rodata._ZTV10AminoAcids[_ZTV10AminoAcids]+0x48): undefined
reference to `alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTV10AminoAcids[_ZTV10AminoAcids]+0x60): undefined
reference to `alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTV10AminoAcids[_ZTV10AminoAcids]+0x70): undefined
reference to `alphabet::get_frequencies_from_counts(std::valarray<double>
const&, double) const'
/tmp/ccfEMWL0.o:(.rodata._ZTC10AminoAcids0_8alphabet[_ZTV10AminoAcids]+0x30):
undefined reference to `typeinfo for alphabet'
/tmp/ccfEMWL0.o:(.rodata._ZTC10AminoAcids0_8alphabet[_ZTV10AminoAcids]+0x48):
undefined reference to `alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTC10AminoAcids0_8alphabet[_ZTV10AminoAcids]+0x60):
undefined reference to `alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTC10AminoAcids0_8alphabet[_ZTV10AminoAcids]+0x70):
undefined reference to
`alphabet::get_frequencies_from_counts(std::valarray<double> const&, double)
const'
/tmp/ccfEMWL0.o:(.rodata._ZTV3RNA[_ZTV3RNA]+0x48): undefined reference to
`alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTV3RNA[_ZTV3RNA]+0x60): undefined reference to
`alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTV3RNA[_ZTV3RNA]+0x70): undefined reference to
`alphabet::get_frequencies_from_counts(std::valarray<double> const&, double)
const'
/tmp/ccfEMWL0.o:(.rodata._ZTC3RNA0_11Nucleotides[_ZTV3RNA]+0x48): undefined
reference to `alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTC3RNA0_11Nucleotides[_ZTV3RNA]+0x60): undefined
reference to `alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTC3RNA0_11Nucleotides[_ZTV3RNA]+0x70): undefined
reference to `alphabet::get_frequencies_from_counts(std::valarray<double>
const&, double) const'
/tmp/ccfEMWL0.o:(.rodata._ZTC3RNA0_8alphabet[_ZTV3RNA]+0x30): undefined
reference to `typeinfo for alphabet'
/tmp/ccfEMWL0.o:(.rodata._ZTC3RNA0_8alphabet[_ZTV3RNA]+0x48): undefined
reference to `alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTC3RNA0_8alphabet[_ZTV3RNA]+0x60): undefined
reference to `alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTC3RNA0_8alphabet[_ZTV3RNA]+0x70): undefined
reference to `alphabet::get_frequencies_from_counts(std::valarray<double>
const&, double) const'
/tmp/ccfEMWL0.o:(.rodata._ZTV3DNA[_ZTV3DNA]+0x48): undefined reference to
`alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTV3DNA[_ZTV3DNA]+0x60): undefined reference to
`alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTV3DNA[_ZTV3DNA]+0x70): undefined reference to
`alphabet::get_frequencies_from_counts(std::valarray<double> const&, double)
const'
/tmp/ccfEMWL0.o:(.rodata._ZTC3DNA0_11Nucleotides[_ZTV3DNA]+0x48): undefined
reference to `alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTC3DNA0_11Nucleotides[_ZTV3DNA]+0x60): undefined
reference to `alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTC3DNA0_11Nucleotides[_ZTV3DNA]+0x70): undefined
reference to `alphabet::get_frequencies_from_counts(std::valarray<double>
const&, double) const'
/tmp/ccfEMWL0.o:(.rodata._ZTC3DNA0_8alphabet[_ZTV3DNA]+0x30): undefined
reference to `typeinfo for alphabet'
/tmp/ccfEMWL0.o:(.rodata._ZTC3DNA0_8alphabet[_ZTV3DNA]+0x48): undefined
reference to `alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTC3DNA0_8alphabet[_ZTV3DNA]+0x60): undefined
reference to `alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTC3DNA0_8alphabet[_ZTV3DNA]+0x70): undefined
reference to `alphabet::get_frequencies_from_counts(std::valarray<double>
const&, double) const'
/tmp/ccfEMWL0.o:(.rodata._ZTV11Nucleotides[_ZTV11Nucleotides]+0x48): undefined
reference to `alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTV11Nucleotides[_ZTV11Nucleotides]+0x60): undefined
reference to `alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTV11Nucleotides[_ZTV11Nucleotides]+0x70): undefined
reference to `alphabet::get_frequencies_from_counts(std::valarray<double>
const&, double) const'
/tmp/ccfEMWL0.o:(.rodata._ZTC11Nucleotides0_8alphabet[_ZTV11Nucleotides]+0x30):
undefined reference to `typeinfo for alphabet'
/tmp/ccfEMWL0.o:(.rodata._ZTC11Nucleotides0_8alphabet[_ZTV11Nucleotides]+0x48):
undefined reference to `alphabet::print() const'
/tmp/ccfEMWL0.o:(.rodata._ZTC11Nucleotides0_8alphabet[_ZTV11Nucleotides]+0x60):
undefined reference to `alphabet::setup_letter_classes()'
/tmp/ccfEMWL0.o:(.rodata._ZTC11Nucleotides0_8alphabet[_ZTV11Nucleotides]+0x70):
undefined reference to
`alphabet::get_frequencies_from_counts(std::valarray<double> const&, double)
const'
/tmp/ccfEMWL0.o:(.rodata._ZTI10AminoAcids[_ZTI10AminoAcids]+0x10): undefined
reference to `typeinfo for alphabet'
/tmp/ccfEMWL0.o:(.rodata._ZTI11Nucleotides[_ZTI11Nucleotides]+0x10): undefined
reference to `typeinfo for alphabet'
collect2: error: ld returned 1 exit status

All the errors go away if you change class alphabet to not have virtual public
inheritance, by removing the word "virtual".



More information about the Gcc-bugs mailing list