Hi!

I have the problem trying to load several dinamical library with
option RTLD_GLOBAL.
It's simplified variant of the project.

When start we get:
LaLaLa-1
LaLaLa-1

Must be:
LaLaLa-1
LaLaLa-2

Help me to subscribe the global and local data for dinamical library when I
compile library contains several object files?

//----------------------------------
// start.cpp
//----------------------------------

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <dlfcn.h>

typedef void (*PLibWrapper)(); // LibWrap

int main() {
void* hLibModule1;
void* hLibModule2;
PLibWrapper Wrapper1;
PLibWrapper Wrapper2;

hLibModule1 = dlopen("./lib111.so", RTLD_LAZY|RTLD_GLOBAL);
if ( !hLibModule1 ) return 0;

hLibModule2 = dlopen("./lib222.so", RTLD_LAZY|RTLD_GLOBAL);
if ( !hLibModule2 ) return 0;

Wrapper1 = (PLibWrapper)dlsym( hLibModule1, "LibWrap" );
if (!Wrapper1) return 0;

Wrapper2 = (PLibWrapper)dlsym( hLibModule2, "LibWrap" );
if (!Wrapper2) return 0;

(*Wrapper1)();
(*Wrapper2)();

dlclose( hLibModule1 );
dlclose( hLibModule2 );
return 1;
}

//----------------------------------
// lib111.cpp
//----------------------------------
#include <stdio.h>
#include <stdlib.h>

static void Print( ) {
printf("LaLaLa-1\n");
}

void* LibraryEnter = (void*)Print;

//----------------------------------
// lib222.cpp
//----------------------------------
#include <stdio.h>
#include <stdlib.h>

static void Print( ) {
printf("LaLaLa-2\n");
}

void* LibraryEnter = (void*)Print;

//----------------------------------
// common.cpp
//----------------------------------
#include <stdio.h>
#include <stdlib.h>

typedef void (*PLibMain)(void);

extern void* LibraryEnter;

extern "C" void LibWrap( ) {
(*((PLibMain)LibraryEnter))();
}

//----------------------------------
// makefile
//----------------------------------

g++ -fPIC -c lib111.cpp
g++ -fPIC -c lib222.cpp
g++ -fPIC -c common.cpp
g++ -fPIC -shared -o lib111.so common.o lib111.o
g++ -fPIC -shared -o lib222.so common.o lib222.o

g++ -c start.cpp
g++ start.o -ldl -o start

//----------------------------------

- Maxim