Forum > macOS / Mac OS X
[solved] *.dylib and "initialization" section under Mac
Frantic:
Hi all!
I'm trying to make a *.dylib with FPC/Lazarus for Mac and use it from Objective-C code. How can I do that correctly?
The way I do that now is compiling *.dylib with "exports" section, which lists all functions I want to export (all declared as "cdecl"). Next, I just drag&drop *.dylib file into "Frameworks" section of Xcode project and create *.h file with exact same declaration as in my lazarus sources. When I run app from Xcode my *.dylib just happens to be loaded and I can call exported functions from it.
But this way has one big problem - "initialization" sections of all units (including system ones such as Classes, SysUtils, CThreads and so on) don't get called. Why? Can anyone help me with that?
Jonas Maebe:
--- Quote from: Frantic on January 09, 2011, 01:00:15 pm ---Hi all!
I'm trying to make a *.dylib with FPC/Lazarus for Mac and use it from Objective-C code. How can I do that correctly?
The way I do that now is compiling *.dylib with "exports" section, which lists all functions I want to export (all declared as "cdecl"). Next, I just drag&drop *.dylib file into "Frameworks" section of Xcode project and create *.h file with exact same declaration as in my lazarus sources. When I run app from Xcode my *.dylib just happens to be loaded and I can call exported functions from it.
--- End quote ---
That's the correct way to do it.
--- Quote ---But this way has one big problem - "initialization" sections of all units (including system ones such as Classes, SysUtils, CThreads and so on) don't get called. Why?
--- End quote ---
I don't know, because all tests in the FPC testsuite that check whether the unit initialisation sections are run for dynamic libraries work correctly for Mac OS X. You don't have to do anything special for that either.
Frantic:
Thank you for your reply. But somehow "initialization" doesn't work for me. Where can I find examples/testcases on Lazarus dylib Mac usage?
marcov:
Try to call FPC_INITIALIZE and FPC_FINALIZE from C before and after usage.
Jonas Maebe:
--- Quote from: Frantic on January 10, 2011, 12:55:47 pm ---Thank you for your reply. But somehow "initialization" doesn't work for me. Where can I find examples/testcases on Lazarus dylib Mac usage?
--- End quote ---
I can't think of any reason why things would be different with Lazarus compared to without Lazarus.
The FPC test can be found here (you need all mentioned files):
* http://svn.freepascal.org/svn/fpc/trunk/tests/webtbs/tw8730a.pp
* http://svn.freepascal.org/svn/fpc/trunk/tests/webtbs/uw8730a.pp
* http://svn.freepascal.org/svn/fpc/trunk/tests/webtbs/tw8730b.pp
* http://svn.freepascal.org/svn/fpc/trunk/tests/webtbs/uw8730b.pp
* http://svn.freepascal.org/svn/fpc/trunk/tests/webtbs/tw8730c.pp
Compile the tw* files in alphabetical order, then run tw8730c. It will print an error message if something went wrong.
Also, which FPC version are you using?
Navigation
[0] Message Index
[#] Next page