This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcc-2.91.2 AIX 4.3 shared library bug?


Hi there,

I tried to build a shared C++ library with gcc-2.95.2 on AIX4.3
and load it with the dlopen function:
gcc was configured with option --shared.

// -- file main.c ---
#include <dlfct.h>
#include <stdio.h>
main() {
  void* h = dlopen("./mylib.so");
  if (!h) {
    puts(dlerror());
  else
    puts("ok");
}


// -- file mylib.cxx --
#include <iostream>

struct dummy {
  dummy() { cout << "global constructor\n"; }
};

dummy d;
// -- end of file


gcc -o main main.c
c++ -o myfile.o -c myfile.cxx

1. Using c++ -shared
  
  c++ -shared -o mylib.so myfile.o
  => linker warnings about duplicate symbols 
     _GLOBAL__DI, _GLOBAL__DD, ._GLOBAL__DI, ._GLOBAL__DD

  result of main program:
  => Exec format error

2. Using gcc -lstdc++-ar:
   gcc -shared -o mylib.so myfile.o -lstdc++-ar
   => no linker warnings
    
   result of main program:
  => Exec format error

3. Using the AIX system linker:

   ld -bhalt:4 -bM:SRE -bE:exports.exp -H512 -T512 -bnoentry -bbigtoc \
      -o mylib.so myfile.o -L<libstdc++-path> -lstdc++-ar -L<libgcc-path> \
      -lgcc -lc 

   result of main program:
   => ok

   Problem: no global constructors/destructors are called within
   mylib.so. However it seems that the global constructors of libstdc++ 
   are called (cout etc. works fine).

Is this a bug in gcc or am I doing something wrong?


-- Markus













Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]