0

I have a native win32 dll which has been built from 3 static libraries using Visual Studio 12 2013.

Two of these static libraries are static 'plugins' which rely on global initialisers to 'register' with the third library.

This means I need code to be executed when the dll is loaded. I have a function:

int NullDevicePlugin_construct() {
    inititalise_plugin();
    return 0;
}
int g_NullDevicePlugin_initialiser = NullDevicePlugin_construct();

This function never gets called. I have checked the symbols in the static lib where this code resides, and I have:

00C 00000000 SECT5  notype       Static       | .CRT$XCU
    Section length    4, #relocs    1, #linenums    0, checksum        0
00E 00000000 SECT5  notype       Static       | _g_NullDevicePlugin_initialiser$initializer$

I have also linked the dll which contains this static lib with /OPT:NOREF and /OPT:NOICF.

This is a mobile cross-development project, and for Android and iOS I use:

__attribute__((constructor)) static void NullDevicePlugin_constructor()

decoration which gets called on both platforms.

I have also tried: __attribute__((constructor)) equivalent in VC?, but this does not work for me.

The c# code calls into the native dll with no problems.

Can anyone help with this?

Many thanks

Community
  • 1
  • 1
Jon Slater
  • 41
  • 4
  • Static initialization is a strong CRT implementation detail. You are using more than one, that rarely comes to a good end. The Microsoft CRT doesn't know beans about GCC attributes. – Hans Passant Oct 02 '15 at 09:46
  • Yes, that's why I said 'for Android and iOS I use..'. Anyway, why is using more than one bad? I'm not concerned with initialisation order, so I am unaffected by the 'static initialisation order fiasco'. – Jon Slater Oct 02 '15 at 10:01
  • You should try to make a [mcve]. I could build a C++ dll and call some functions from a C process without exhibiting such problem - but I could not use C# so long... – Serge Ballesta Oct 02 '15 at 11:54
  • thanks @SergeBallesta that's an excellent suggestion, one which I was just coming round to myself. hopefully i'll get to the bottom of this, then i'll post the result – Jon Slater Oct 02 '15 at 12:04

0 Answers0