Bug#266110: undefined symbols when using specials char_traits
Package: libstdc++5-3.3-dev
Version: 3.3.4-9
(note: also appearing with 3.2.x and 3.3.x under sarge and unstable)
I'm getting some unresolved symbols when trying to compile C++ programs
using specific char_traits. For example this small program does NOT
compile:
----------8<----------------------------------------
#include "iostream"
#include "string"
using namespace std;
enum TestType { one = 't', two, three };
template<typename CharType>
class TestClass
: public std::basic_string<CharType>
{
public:
virtual void test(const CharType *test)
{
(*this).assign(test);
}
};
int main(void)
{
TestClass<TestType> test;
TestType t = one;
test.test(&t);
// cout << test << endl;
return 0;
}
----8<-------------------------------------------
the compilation brings out these errors:
mathieu@c-l-175:~/tests/char_traits$ g++ -o main main.cpp
/tmp/ccjDfp6k.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE6assignEPKS_+0xd): In function `std::basic_string<TestType, std::char_traits<TestType>, std::allocator<TestType> >::assign(TestType const*)':
: undefined reference to `std::char_traits<TestType>::length(TestType
const*)'
/tmp/ccjDfp6k.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE6assignEPKS_j+0x151): In function `std::basic_string<TestType, std::char_traits<TestType>, std::allocator<TestType> >::assign(TestType const*, unsigned)':
: undefined reference to `std::char_traits<TestType>::copy(TestType*,
TestType const*, unsigned)'
/tmp/ccjDfp6k.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE6assignEPKS_j+0x17c): In function `std::basic_string<TestType, std::char_traits<TestType>, std::allocator<TestType> >::assign(TestType const*, unsigned)':
: undefined reference to `std::char_traits<TestType>::move(TestType*,
TestType const*, unsigned)'
/tmp/ccjDfp6k.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE9_M_mutateEjjj+0x147): In function `std::basic_string<TestType, std::char_traits<TestType>, std::allocator<TestType> >::_M_mutate(unsigned, unsigned, unsigned)':
: undefined reference to `std::char_traits<TestType>::copy(TestType*,
TestType const*, unsigned)'
/tmp/ccjDfp6k.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE9_M_mutateEjjj+0x182): In function `std::basic_string<TestType, std::char_traits<TestType>, std::allocator<TestType> >::_M_mutate(unsigned, unsigned, unsigned)':
: undefined reference to `std::char_traits<TestType>::copy(TestType*,
TestType const*, unsigned)'
/tmp/ccjDfp6k.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE9_M_mutateEjjj+0x27c): In function `std::basic_string<TestType, std::char_traits<TestType>, std::allocator<TestType> >::_M_mutate(unsigned, unsigned, unsigned)':
: undefined reference to `std::char_traits<TestType>::move(TestType*,
TestType const*, unsigned)'
/tmp/ccjDfp6k.o(.gnu.linkonce.t._ZNSbI8TestTypeSt11char_traitsIS_ESaIS_EE13_S_copy_charsEPS_PKS_S6_+0x23): In function `std::basic_string<TestType, std::char_traits<TestType>, std::allocator<TestType> >::_S_copy_chars(TestType*, TestType const*, TestType const*)':
: undefined reference to `std::char_traits<TestType>::copy(TestType*,
TestType const*, unsigned)'
collect2: ld returned 1 exit status
the following compilation brings out these errors:
*************************
As far as I have looked, the char_traits are correctly _declared_ for
every template, but the member functions of the struct are defined only
when using 'char' or 'wchar_t' as template type.
Again, this bug has been fixed in the new version of the libstdc++
(version 6 provided with g++-3.4), and making an adapted copy-paste of
the 'char_traits.h' file should be an acceptable solution (works fine
for me).
Best Regards,
Mathieu Fluhr
Reply to: