3 ms·
It's possible, just not officially supported nor straightforward. You need to run the GC yourself and all this kind of stuff. https://stackoverflow.com/questio
by maattdd 6y ago
It's possible, just not officially supported nor straightforward. You need to run the GC yourself and all this kind of stuff.
https://stackoverflow.com/questions/32916684/can-a-crystal-library-be-statically-linked-to-from-c https://stackoverflow.com/questions/32916684/can-a-crystal-l...
https://gist.github.com/Papierkorb/02d6ba53c28b5035a80bf7695f4706bb https://gist.github.com/Papierkorb/02d6ba53c28b5035a80bf7695...
- filleduchaos 6y agoIt's not officially supported yes but having actually done it multiple times for multiple projects I don't see how it's not straightforward. - You do the linking yourself, so that you can pass the flags to produce the kind of library you want. This is something the Crystal compiler helps with (it spits out the LDFLAGS that you need). - Calling `GC.init` when your library is loaded if you want to use garbage collection seems a bit obvious in its necessity. Using `GC.free` to free memory that has gone beyond Crystal boundaries follows naturally (and most libraries have custom `free_*` functions to clean up complex objects). The main complexity you have to write a C-friendly API for the library, but that's something that you have to do with C++ and so on as well
- maattdd 6y agoYou also need to handle the event loop yourself ; otherwise you end up using a language which is sub-Crystal.
- filleduchaos 6y agoWhat do you mean by "handle the event loop yourself"? Again, have you ever actually tried to do this or are you just speculating?