Author Topic: Including external libraries in modules  (Read 1619 times)

bgardon

  • New to the forum
  • *
  • Posts: 2
Including external libraries in modules
« on: February 03, 2017, 01:53:14 AM »
I'm working on developing some extensions to an existing module and I want to include an external library. I've finally figured out how to get my code to link against the library, however standard library functions in the library such as malloc do not seem to have anything to link against since the implementation of those functions in ML seems to be a bit different (malloc, for example, appears to be a macro). Does anyone know how I could get the library working with the standard library functions it needs without having to go through and include dryos.h or something in all the library source files?

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12258
  • Emergencies only
Re: Including external libraries in modules
« Reply #1 on: February 03, 2017, 09:40:51 AM »
Lua includes a subset of dietlibc, so you can look there for an example.

You may be also interested in these (they use external libraries as well):
https://bitbucket.org/hudson/magic-lantern/pull-requests/705
https://bitbucket.org/hudson/magic-lantern/branch/hdparm
https://bitbucket.org/hudson/magic-lantern/src/unified/modules/tinypy/
http://www.magiclantern.fm/forum/index.php?topic=14853.0

Currently, malloc is defined as a macro, but other than that, it works as plain malloc (so you could try to include mem.h in your library). Unless you have a good reason to use a custom allocator (we had for Lua).

I'd also like to have more stdlib functionality in ML core, so any help is welcome in this direction.