how to create ".dylib"s for Mac OS X?
BlitzMax Forums/BlitzMax Programming/how to create ".dylib"s for Mac OS X?
| ||
Good morning! I'll soon have to decide whether to use BlitzMAX or PureBasic for my developments. The most important aspect will be whether I will be able to produce dynamically loadable libraries for all supported platforms (i.e., DLLs, DyLibs, Shared Objects) I would really prefer to use BlitzMAX, but - I managed to build and use a DLL under Windows (XP) - when I try the same under Mac OS X, the application crashes - I have not yet tried the same under Linux (as Mac OS X is more important) Has anybody managed to build DyLibs and Shared Objects? Here is my approach for Mac OS X: - the library (DLLTest_DLL.bmx): strict framework brl.blitz function DoubleIt:int (Value:int) ' GCEnter() return 2*Value end function - the definition file (DLLTest_DLL.def, bmk did not complain - it might therefore be correct) EXPORTS DoubleIt=bb_DoubleIt - the command to build the library /Applications/BlitzMax/bin/bmk makelib DLLTest_DLL.bmx - the test program (DLLTest.bmx) Strict Framework brl.blitz Extern "C" ' see /usr/include/dlfcn.h, POSIX part only function dlclose:byte ptr (Handle:byte ptr) function dlerror$z () function dlopen:byte ptr (Path$z, Mode:int) function dlsym:byte ptr (Handle:byte ptr, Symbol$z) End Extern Const RTLD_LAZY = $01 ' lazy function call binding Const RTLD_NOW = $02 ' immediate function call binding Const RTLD_LOCAL = $04 Const RTLD_GLOBAL = $08 Local Library:Byte Ptr = dlopen("DLLTest_DLL", RTLD_GLOBAL | RTLD_NOW) If (Not Library) Then WriteStdout "Library could not be loaded~n" Throw "library not found" Else WriteStdout "Library loaded~n" End If WriteStdout "dlerror() = " + dlerror() + "~n" Local DoubleIt:Int (Value:Int) DoubleIt = dlsym(Library,"DoubleIt") If (Not DoubleIt) Then WriteStdout "unable to obtain symbol 'DoubleIt'~n" End If WriteStdout "DoubleIt(10) = " + DoubleIt(10) WriteStdout "Yippee!~n" dlclose(Library) This test is a modification of what I found in this forum and by looking into the file "/usr/include/dlfcn.h" If I start the test, the application crashes and I get the following dump Does anybody have a clue what is going wrong here? Thanks in advance for any help! |
| ||
There is another strange problem: somebody in this forum mentioned the use of "GCEnter()" whithin the DLL functions in order to let the built-in garbage collector run properly. Under Win32, I am able to build a DLL which calls this function - under Mac OS X, I am not. Here is the linker error message: Does anybody have an idea why? |
| ||
Use dll‘s on MacOS X????? Is this possible!!!!!!! |
| ||
Use dll‘s on MacOS X????? Is this possible!!!!!!! No. |
| ||
@MacSven: No, but using the equivalent (a MacOS shared library - a .dylib) is possible. |
| ||
Has anybody managed to build DyLibs and Shared Objects? I've tried to build a screensaver framework... no joy - doesn't like the non-relocatable assembler which BlitzMax creates. (well, that's what the error complains about). It's possible that a dynamic library *may* work, but I have not tried it yet - no need. |
| ||
It's possible that a dynamic library *may* work, but I have not tried it yet - no need. Ah, so a dylib and a shared object/library are two different things.. |
| ||
Hello! Thanks for all your answers. I've (almost immediately) managed to produce a .dylib using the free XCode development system - but I will have to code in C (or C++) then, which I would like to avoid. But, since PureBasic is currently unable to build .dylibs as well, it seems as if I would have to continue with C. Is there any chance that BlitzMAX could "learn" how to produce .dylibs? (compiler/assembler flag, injecting an intermediate (C/C++) code into XCode, or some other weird but automatable solution?) Thanks in advance for any answers. |
| ||
Brucey, you tried screensavers that support blitzmax code on the mac? How did that go in general? I tried it too but all that objective c framework stuff is not my forte. |
| ||
Hello! I just tested BlitzMax 1.33rc5 - with the same results as before... :-( Actually, this means that it is impossible to produce .dylibs for MacOS X with BlitzMax |
| ||
If it's impossible then why would the feature be in there? |
| ||
Hello again (after quite a while) I just tried to use the current version of BlitzMAX (i.e. 1.37) to create and load a .dylib - and failed again! Using the approach mentioned above - the DLLTest is able to load the ".dylib" (it claims so, at least) but never finds the exported symbol - the DLLTest crashes on the invokation of "dlclose" Has anybody else found a way to create DLLs/DyLibs/SOs? (i.e. dynamically loadable libraries an any supported platform) |