www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Equivalent of DllMain on OSX?

reply "Mark Isaacson" <turck11 hotmail.com> writes:
I am presently trying to port a driver I wrote for Windows to 
OSX. The one thing standing in my way is figuring out how to get 
the equivalent of DllMain on OSX.

I need a place to call Runtime.initialize() and whatnot.

Reading the wiki, it seemed like `shared static this()`  was the 
appropriate construct to use, and indeed, when I run the test 
program from:
http://dlang.org/dll-linux.html#dso9

I get the desired results: namely, I see that the `shared static 
this()` in that test program is called the desired point.

When I try the same thing in my driver, it is never executed.

Are dylibs on OSX not supported still (I saw some very old 
threads from 2012 stating as much)? Does it matter that I have 
multiple modules in the driver? Any help would be appreciated.

I shall endeavor to get the modified driver code into a state 
where I can link it as well.
Jul 25 2014
parent reply "Joakim" <dlang joakim.airpost.net> writes:
On Friday, 25 July 2014 at 21:23:00 UTC, Mark Isaacson wrote:
 I am presently trying to port a driver I wrote for Windows to 
 OSX. The one thing standing in my way is figuring out how to 
 get the equivalent of DllMain on OSX.

 I need a place to call Runtime.initialize() and whatnot.

 Reading the wiki, it seemed like `shared static this()`  was 
 the appropriate construct to use, and indeed, when I run the 
 test program from:
 http://dlang.org/dll-linux.html#dso9

 I get the desired results: namely, I see that the `shared 
 static this()` in that test program is called the desired point.

 When I try the same thing in my driver, it is never executed.

 Are dylibs on OSX not supported still (I saw some very old 
 threads from 2012 stating as much)? Does it matter that I have 
 multiple modules in the driver? Any help would be appreciated.

 I shall endeavor to get the modified driver code into a state 
 where I can link it as well.
Loading multiple D shared libraries isn't supported on OS X yet, see these warnings in druntime: https://github.com/D-Programming-Language/druntime/blob/master/src/rt/sections_osx.d#L198 If you only have a single D shared library, I think it's possible, you just may have to tweak dmd/druntime or your build process a bit. I think Martin Nowak or Jacob Carlborg can really answer your questions, as Martin wrote a lot of that code and Jacob seems to follow it closely, whereas I don't use OS X but looked at that code when porting to Android.
Jul 25 2014
parent "Mark Isaacson" <turck11 hotmail.com> writes:
 Loading multiple D shared libraries isn't supported on OS X 
 yet, see these warnings in druntime:

 https://github.com/D-Programming-Language/druntime/blob/master/src/rt/sections_osx.d#L198

 If you only have a single D shared library, I think it's 
 possible, you just may have to tweak dmd/druntime or your build 
 process a bit.

 I think Martin Nowak or Jacob Carlborg can really answer your 
 questions, as Martin wrote a lot of that code and Jacob seems 
 to follow it closely, whereas I don't use OS X but looked at 
 that code when porting to Android.
It would only be a single shared library. Finally got the code publicly available: https://github.com/markisaa/presto-odbc/blob/osxCompile/driver/driver.d#L61 It should compile on OSX with a simple `make clean all` Testing would require installing the iODBC driver manager and pressing the 'Add Driver' button, possibly making a new User DSN, and possibly pressing 'Test'.
Jul 25 2014