Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Problem building C++ shared library

I am using uClinux-dist with MMU and the gcc 4.1.2 binary toolchain, and I am having a problem with g++ when building a shared library.

A test:

#include <stdio.h>
int main(void)
{
  printf("hello world\n");
}

gcc build works:

$ /data/nios/nios2-linux/toolchain-mmu/x86-linux2/bin/nios2-linux-gnu-gcc -DEMBED -mhw-mul -mno-hw-mulx -mno-hw-div -shared -o hello.c.o -c /data/nios/hello.c
$ /data/nios/nios2-linux/toolchain-mmu/x86-linux2/bin/nios2-linux-gnu-gcc -mhw-mul -mno-hw-mulx -mno-hw-div -shared -Wl,-soname,libhelloworldc.so -o libhelloworldc.so hello.c.o

Same thing, with g++:

$ /data/nios/nios2-linux/toolchain-mmu/x86-linux2/bin/nios2-linux-gnu-g++ -DEMBED -mhw-mul -mno-hw-mulx -mno-hw-div -shared -o hello.c.o -c /data/nios/hello.c
$ /data/nios/nios2-linux/toolchain-mmu/x86-linux2/bin/nios2-linux-gnu-g++ -mhw-mul -mno-hw-mulx -mno-hw-div -shared -Wl,-soname,libhelloworldc.so -o libhelloworldc.so hello.c.o
/data/nios/nios2-linux/toolchain-mmu/x86-linux2/bin/../lib/gcc/nios2-linux-gnu/4.1.2/../../../../nios2-linux-gnu/bin/ld: fde encoding in hello.c.o(.eh_frame) prevents .eh_frame_hdr table being created.

The library actually gets created, but a program using a C++ library built like this gives a SEGV on start. If I build a C++ helloworld executable using g++ and make sure not to use the "-shared" option, then it works. Ideas?

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    Would you please give me some information by setting

    
    echo 1 > /proc/sys/kernel/print-fatal-signals
    
    .

    And please try the switch '-fPIC', if possible.

    Kazu
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Looks like the problem I am running into is not because of this warning. helloworld works with -fPIC although I still get the linker warnings.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    OK, I accidentally covered this up before, but I think this is my real problem in addition to the .eh_frame_hdr table warnings. I can't reproduce this with helloworld, but when I build my executable that uses two C++ shared libraries, I get:

    /data/nios/nios2-linux/toolchain-mmu/x86-linux2/bin/../lib/gcc/nios2-linux-gnu/4.1.2/../../../../nios2-linux-gnu/bin/ld: testserver: hidden symbol `__divsi3_table' in /data/nios/nios2-linux/toolchain-mmu/x86-linux2/bin/../lib/gcc/nios2-linux-gnu/4.1.2/libgcc.a(lib2-divtable.o) is referenced by DSO
    /data/nios/nios2-linux/toolchain-mmu/x86-linux2/bin/../lib/gcc/nios2-linux-gnu/4.1.2/../../../../nios2-linux-gnu/bin/ld: final link failed: Nonrepresentable section on output

    UPDATE: The .eh_frame_hdr warnings seem to be hiding actual link errors. Adding -lgcc -lc to my libraries got me past that error.