In Wolfram LibrayLink, a C function more or less will call other auxiliary C functions. Below is a instance:

In this example, two auxiliary functions FindSpan() and BasisFuns() were involved in CurvePoint(). However, the Wolfram LibraryLink User Guides doesn’t cover this aspect.

To deal with this problem, a workaround I come up with is building three wrapper functions FindSpan(), BasisFuns() and calcCurve() separately, then calling them in Mathematica, respectively.

=================

=================

1 Answer

1

=================

I am not sure I understand your question, as it really does read like “How to call a function in C?”, which is a C question, not a Mathematica one, as @blochwave said.

Maybe you are asking, how to call a function with a signature like this:

DLLEXPORT int fun(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res)

Just don’t call it! It’s not meant to be called directly by the programmer. There is never any reason to. It’s meant to be called by the Mathematica kernel only. That is why it has this special, rigid signature that the programmer must conform to when implementing LibraryLink functions.

You are probably trying to do this:

DLLEXPORT int fun1(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {

/* do something */

}

DLLEXPORT int fun2(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {

/* how do I call fun1() here? */

}

Such a design makes no sense. Don’t do it.

/* this is some function written by you, with a task-appropriate signature */

double myfun(double x) { return x*x; }

DLLEXPORT int fun1(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {

/* call myfun() here */

}

DLLEXPORT int fun2(WolframLibraryData libData, mint Argc, MArgument *Args, MArgument Res) {

/* call myfun() here */

}

fun1() can be a wrapper function for myfun(). myfun() implements some functionality and fun1() makes this functionality accessible from Mathematica.

fun2() can also make use of myfun(), while doing additional things.

The signature (arguments and return type) of myfun() is dictated by what it does. It should be easy to call for you. The signature of fun1() is dictated by the rules of LibraryLink. It must have a certain signature in order to be callable directly form Mathematica.

I have to agree with @blochwave that many of your recent questions are a result of not being sufficiently familiar with C. They aren’t really about Mathematica or LibraryLink, even if they come up while you are trying to work with LibraryLink.

I would recommend getting familiar with C before trying to use LibraryLink. LibraryLink is not a great vehicle for learning the basics of C programming. Getting comfortable with C first would avoid most of these questions.