I am testing the delay load at startup-time on Linux. I have 3 files: sharedlib.cpp, sharedlib.hxx, and main.cpp.
****** source for main.cpp
extern "C" void func1(void);

int main(int argc, char* argv[])
{
if (argc > 1)
func1();
}
******* source for sharedlib.cpp
#include <stdio.h>
#include "sharedlib.hxx"

void lm_init_module(void);

static InitClass initMe(lm_init_module);

void lm_init_module(void)
{
printf ("in lm_init_module()\n");
}

extern "C" void func1(void)
{
printf("in func1()\n");
}
******* source for sharedlib.hxx
class InitClass{
public:
InitClass(void (*p)())
{
(*p)();
}
};
******
I built a shared library lnxsharedlib.sl with the following command:

/usr/bin/g++ sharedlib.cpp -c -fPIC -m64 -g -o lnxsharedlib.o

/usr/bin/g++ -shared -o liblnxsharedlib.so lnxsharedlib.o



I built the executable lnxsharedlib with the following command:

/usr/bin/g++ main.cpp -m64 -o lnxsharedlib -L/mnt/tcdev/cvk_tc2007 -Wl,-a,shared –llnxsharedlib



When I invoke lnxsharedlib, I didn’t expect to see the printf line “in lm_init_module()”, but it is printed. Can I use other compiler/linker options to get the liblnxsharedlib.sl not to be loaded at startup-time?. I tried to link it without the –Wl,-a,shared also.

BTW On Windows, Solaris, and AIX, the line "in lm_init_module" is not printed (the shared library is not loaded at startup time)