problem with libg++-2.8.0 rpm
Adam P. Jenkins
ajenkins@cs.umass.edu
Fri Jan 23 02:29:00 GMT 1998
Hi, I downloaded and installed libg++-2.8.0-1.i386.rpm and installed
it, along with gcc-2.8.0. When linking C++ programs with it that use
the standard string class, I get a bunch of errors about different
parts of string being undefined. I've found the problem too, and a
solution, which I state after this. For example:
------------- tmp.cc -------
#include <iostream.h>
#include <string>
int main()
{
string s = "hello";
cout << s << endl;
return 0;
}
----------------------------
[dwarin:~/devel/c]$ g++ -v tmp.cc
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.8.0/specs
gcc version 2.8.0
/usr/lib/gcc-lib/i386-redhat-linux/2.8.0/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=8 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Di386 -Asystem(unix) -Acpu(i386) -Amachine(i386) -D__i386__ -Asystem(unix) -Acpu(i386) -Amachine(i386) tmp.cc /tmp/cca24977.ii
GNU CPP version 2.8.0 (i386 GNU/Linux with ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/include/g++
/usr/local/include
/usr/lib/gcc-lib/i386-redhat-linux/2.8.0/include
/usr/include
End of search list.
/usr/lib/gcc-lib/i386-redhat-linux/2.8.0/cc1plus /tmp/cca24977.ii -quiet -dumpbase tmp.cc -version -o /tmp/cca24977.s
GNU C++ version 2.8.0 (i386-redhat-linux) compiled by GNU C version 2.8.0.
as -V -Qy -o /tmp/cca249771.o /tmp/cca24977.s
GNU assembler version 2.8.1 (i686-pc-linux-gnu), using BFD version linux-2.8.1.0.1
ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i386-redhat-linux/2.8.0/crtbegin.o -L/usr/lib/gcc-lib/i386-redhat-linux/2.8.0 /tmp/cca249771.o -lstdc++ -lm -lgcc -lc -lgcc /usr/lib/gcc-lib/i386-redhat-linux/2.8.0/crtend.o /usr/lib/crtn.o
/tmp/cca249771.o: In function `main':
/tmp/cca249771.o(.text+0x4b): undefined reference to `__ls__H3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b0i0_R7ostreamRCt12basic_string3ZX01ZX11ZX21_R7ostream'
/tmp/cca249771.o: In function `basic_string<char, string_char_traits<char>, __default_alloc_template<false, 0> >::basic_string(char const *)':
/tmp/cca249771.o(.gnu.linkonce.t.__t12basic_string3ZcZt18string_char_traits1ZcZt24__default_alloc_template2b0i0PCc+0xc): undefined reference to `basic_string<char, string_char_traits<char>, __default_alloc_template<false, 0> >::nilRep'
with more "undefined" error messages, all about parts of the string
class. The problem is caused because the library was compiled with
_PTHREADS defined, which causes __NODE_ALLOCATOR_THREADS to be defined
as true in stl_alloc.h. Later in the same file, alloc is defined as
typedef __default_alloc_template<__NODE_ALLOCATOR_THREADS, 0> alloc;
and since alloc is the default template argument for the allocator for
basic_string, what gets instantiated by sinst.cc in libstdc++ is
basic_string<char, string_char_traits<char>,
__default_alloc_template<true, 0> >
^^^^
However, when I compile a program, unless I compile all my programs
with -D_PTHREADS too, I get errors like the above, because if
_PTHREADS isn't defined, then __NODE_ALLOCATOR_THREADS gets defined as
false, so I get a different alloc type, and therefore a different
basic_string than the one in the library. If you notice in the error
messages, you'll see that it's looking for
basic_string<char, string_char_traits<char>,
__default_alloc_template<false, 0> >::*
^^^^^
The solution is just to add #define _PTHREADS to stl_config.h if
you're going to define it when compiling the library.
Adam
More information about the Gcc-bugs
mailing list