Skip to contentSkip to conversation

compile C++ code

DISCUSSION kjlin 4 participants 5 messages Aug 31, 2001 – Sep 3, 2001 MIPS

lore
Share & tools
lore

kjlin

author
#0 lore raw

Hi all,

My host is x86 with redhat 7.0 and install the mips cross-compiler:
1.binutils-mips-linux-2.8.1-2.i386.rpm 2.egcs-mips-linux-1.1.2-3.i386.rpm 3.egcs-c++-mips-linux-1.1.2-4.i386.rpm
4.libc-2.0.6 5.egcs-libstdc++-mips-linux-2.9.0-4.i386.rpm
But when i compile the following C++ code, something wrong!

#include <stdio.h>
class A {
public:

        A();
        virtual void hello();        // with virtual is failed, without virtual is ok.
};
A::A() {printf("A construction!\n");}
void A::hello() { printf("hello\n"); }
main()
{
        A *exam;
        exam->hello();
}

#mips-linux-gcc test.C
/usr/lib/gcc-lib/mips-linux/egcs-2.91.66/libgcc.a(frame.o): In function `decode_uleb128':
/usr/src/redhat/BUILD/egcs-1.1.2/target-mips-linux/gcc/../../gcc/frame.c(.data+0x0): undefined reference to `pthread_create' /usr/mips-linux/bin/ld: bfd assertion fail ../../bfd/elf32-mips.c:5123
mips-linux-gcc: Internal compiler error: program ld got fatal signal 11
#mips-linux-g++ test.C
/usr/mips-linux/lib/libstdc++.so: undefined reference to pthread_create' /usr/mips-linux/lib/libstdc++.so: undefined reference to pthread_getspecific' /usr/mips-linux/lib/libstdc++.so: undefined reference to pthread_once' /usr/mips-linux/lib/libstdc++.so: undefined reference to pthread_key_create' /usr/mips-linux/lib/libstdc++.so: undefined reference to `pthread_setspecific'

If the "virtual" is not used, "virtual void hello();" to "void hello();", mips-linux-gcc compiling is fine but mips-linux-g++ compiling is still the same error. What is going on?
Is it the problem of compiler or library?
How should i do?

Thanks in advance!
KJ

#1 lore raw
Quoted 9 lines · kjlin

Hi all,

My host is x86 with redhat 7.0 and install the mips cross-compiler:
1.binutils-mips-linux-2.8.1-2.i386.rpm 2.egcs-mips-linux-1.1.2-3.i386.rpm 3.egcs-c++-mips-linux-1.1.2-4.i386.rpm
4.libc-2.0.6 5.egcs-libstdc++-mips-linux-2.9.0-4.i386.rpm
But when i compile the following C++ code, something wrong!

This packages are old und buggy.
Please look in the archive where you can download the new toolchains.

Henning Heinold

#2 lore raw
In reply to kjlin
Quoted 12 lines · kjlin

#mips-linux-gcc test.C
/usr/lib/gcc-lib/mips-linux/egcs-2.91.66/libgcc.a(frame.o): In function `decode_uleb128':
/usr/src/redhat/BUILD/egcs-1.1.2/target-mips-linux/gcc/../../gcc/frame.c(.data+0x0): undefined reference to `pthread_create' /usr/mips-linux/bin/ld: bfd assertion fail ../../bfd/elf32-mips.c:5123
mips-linux-gcc: Internal compiler error: program ld got fatal signal 11
#mips-linux-g++ test.C
/usr/mips-linux/lib/libstdc++.so: undefined reference to pthread_create' /usr/mips-linux/lib/libstdc++.so: undefined reference to pthread_getspecific' /usr/mips-linux/lib/libstdc++.so: undefined reference to pthread_once' /usr/mips-linux/lib/libstdc++.so: undefined reference to pthread_key_create' /usr/mips-linux/lib/libstdc++.so: undefined reference to `pthread_setspecific'

It seems you should link with pthread lib :
#mips-linux-g++ test.C -lpthread

I think the libgcc.a should be linked with it ... Can anyone tell us
further on that subject?

Signature · 3 lines
Jean-Christophe ARNU
s/w developer 
Paratronic France
author
#3 lore raw
Quoted 3 lines
Quoted 3 lines

#mips-linux-gcc test.C /usr/lib/gcc-lib/mips-linux/egcs-2.91.66/libgcc.a(frame.o): In function

`decode_uleb128':

Quoted 1 line
Quoted 1 line

/usr/src/redhat/BUILD/egcs-1.1.2/target-mips-linux/gcc/../../gcc/frame.c(.da ta+0x0): undefined reference to `pthread_create'

Quoted 4 lines
Quoted 4 lines

/usr/mips-linux/bin/ld: bfd assertion fail ../../bfd/elf32-mips.c:5123
mips-linux-gcc: Internal compiler error: program ld got fatal signal 11 #mips-linux-g++ test.C
/usr/mips-linux/lib/libstdc++.so: undefined reference to

`pthread_create'

Quoted 1 line
Quoted 1 line

/usr/mips-linux/lib/libstdc++.so: undefined reference to

`pthread_getspecific'

Quoted 2 lines
Quoted 2 lines

/usr/mips-linux/lib/libstdc++.so: undefined reference to `pthread_once' /usr/mips-linux/lib/libstdc++.so: undefined reference to

`pthread_key_create'

Quoted 1 line
Quoted 1 line

/usr/mips-linux/lib/libstdc++.so: undefined reference to

`pthread_setspecific'

Quoted 6 lines
Quoted 1 line

It seems you should link with pthread lib :
#mips-linux-g++ test.C -lpthread

I think the libgcc.a should be linked with it ... Can anyone tell us further on that subject?

Yes, if i link with "-lpthread" , the error is solved.
But i am confused that when i compile the same code with native gcc/g++, it is needless to link with that option.
Why?

#4 lore raw
Quoted 22 lines · kjlin
Quoted 2 lines
Quoted 2 lines

#mips-linux-gcc test.C /usr/lib/gcc-lib/mips-linux/egcs-2.91.66/libgcc.a(frame.o): In function

`decode_uleb128':

Quoted 1 line
Quoted 1 line

/usr/src/redhat/BUILD/egcs-1.1.2/target-mips-linux/gcc/../../gcc/frame.c(.da ta+0x0): undefined reference to `pthread_create'

Quoted 4 lines
Quoted 4 lines

/usr/mips-linux/bin/ld: bfd assertion fail ../../bfd/elf32-mips.c:5123
mips-linux-gcc: Internal compiler error: program ld got fatal signal 11 #mips-linux-g++ test.C
/usr/mips-linux/lib/libstdc++.so: undefined reference to

`pthread_create'

Quoted 1 line
Quoted 1 line

/usr/mips-linux/lib/libstdc++.so: undefined reference to

`pthread_getspecific'

Quoted 2 lines
Quoted 2 lines

/usr/mips-linux/lib/libstdc++.so: undefined reference to `pthread_once' /usr/mips-linux/lib/libstdc++.so: undefined reference to

`pthread_key_create'

Quoted 1 line
Quoted 1 line

/usr/mips-linux/lib/libstdc++.so: undefined reference to

`pthread_setspecific'

Quoted 4 lines
Quoted 1 line

It seems you should link with pthread lib :
#mips-linux-g++ test.C -lpthread

Quoted 7 lines
Quoted 2 lines

I think the libgcc.a should be linked with it ... Can anyone tell us further on that subject?

Yes, if i link with "-lpthread" , the error is solved.
But i am confused that when i compile the same code with native gcc/g++, it is needless to link with that option.
Why?

The problem is that your old toolchain (ld) cannot handle weak symbols.

/Brian