Here is my goal: I want to call external library functions, written in C (not by me), in Mathematica.
I may have found a way to do it using LibraryLink by following this scheme:
- First, for each function that I want to call I have to create a wrapper (not sure it's the correct term) in order to give the good format to the C function so Mathematica can use it.
- Second, use the
FindLibraryfunction where I have to specify the path to find the library. - Third, use the
LibraryFunctionLoadfunction to load the function. For this function I have to specify the name of the function in this library, the list of arguments types needed by the C function and the return type of the C function.
I am not at all familiar with all the concepts that I mentioned so my scheme is probably not correct.
I am not sure how to create this wrapper (if it's the correct term) even if I found some information here.
I also found that it is possible to call external libraries using MathLink (or WSTP) or .NET/Link.
Here are my questions:
- Does my scheme is good or not at all ?
- Some C functions have pointers as arguments or return pointers, do we have something similar in Mathematica ? I found something called
MArgumentfor union of pointers but I don't know if it allows Mathematica to deal with pointers. - Do I have to create special files for the wrapper ? Are they the only files that I need ?
- Does LibraryLink is the best way of dealing with these C libraries ?
Just to precise I am on MacOs BigSur 11.6.2.
Thanks guys.