Questions tagged [librarylink]

Wolfram LibraryLink provides a powerful way to connect external code to Mathematica, enabling high-speed and memory-efficient execution.

From Help:

It [LibraryLink] does this by allowing dynamic libraries to be directly loaded into the Mathematica kernel so that functions in the libraries can be immediately called from Mathematica. Wolfram LibraryLink allows exchanging arbitrary data with the linked library: integers, reals, packed arrays, strings, and arbitrary Mathematica expressions, as well as sending messages and calling back to Mathematica.

Check:

160 questions
24
votes
2 answers

Which Mathematica versions have changed WolframLibraryVersion?

A LibraryLink library compiled with headers having a certain WolframLibraryVersion will not work with Mathematica versions that support only earlier WolframLibraryVersions. For example, a library compiled with M12.0 (WolframLibraryVersion == 5) will…
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
18
votes
1 answer

How to learn the LibraryLink technique for the newcomer?

Description For the built-in programming language(or called Wolfram Language) of Wolfram Mathematica, I think it is much easier and simpler to learn than other computer language(such as C/C++ or java) according to my learning experience. However, in…
xyz
  • 605
  • 4
  • 38
  • 117
14
votes
2 answers

How can I use shared libraries in LibraryLink code and ensure Mathematica will find them?

I need to use shared libraries in some LibraryLink code. The shared library is installed in a custom location because it was also compiled by myself. When I try to load functions from the LibraryLink library, I get LibraryFunction::libload errors…
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
14
votes
2 answers

How to use "managed library expressions" to free the memory?

To return multiple results, Szabolcs (many thanks!) given me a hint in this comment, Namely, using global variable to store the result and then retrieve them with the help of single LibraryLink wrapper function. So I have a trial like this: src = " …
xyz
  • 605
  • 4
  • 38
  • 117
13
votes
1 answer

How to understand shared passing of a MTensor in LibraryLink?

According to the documentation, there are four different type of memory managing when passing a MTensor with LibraryLink: Automatic, "Constant", "Manual" and "Shared". The Automatic and "Manual" is easy to understand, since in both of them, the…
xslittlegrass
  • 27,549
  • 9
  • 97
  • 186
13
votes
1 answer

What are the differences between library call back functions and WolframCompileLibrary macros?

I'm trying to use LibraryLink in Mathematica, and come across some problems. Consider if we have a MTensor m1 which contains a one dimensional double array, and I want to get the data of that array. I come across two methods. One is to use library…
xslittlegrass
  • 27,549
  • 9
  • 97
  • 186
11
votes
1 answer

How to use C language functions in Mathematica?

I'm trying to find out the way to use c-functions in Mathematica (I'm using 14 version) on OS X 10.10. For example I've got this lines of code: #include double helloWorld(double a) { return 2 * a; } Then I've tried to make a shared…
Alex
  • 293
  • 1
  • 10
10
votes
1 answer

How to return a string from LibraryLink?

I need to return a string from a LibraryLink function. The documentation states: When a string is returned as a result, the Wolfram Language accesses the memory to convert it to its own internal string format, but does not attempt to free the…
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
10
votes
1 answer

How to enable C++11 in a platform independent manner?

I need to enable C++11 features when using CreateLibrary. I need a solution which will work with (almost) any compiler on any operating system. Generally, this can be done by passing a certain flag to the compiler. In principle, the syntax will…
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
8
votes
3 answers

Can LibraryLink receive and output a list of strings?

I need to use libraryLink to process a list of strings, I haven't found a suitable example, confused about the types of the arguments and return types. Does libraryLink directly support it, which one is suitable for me?
expression
  • 5,642
  • 1
  • 19
  • 46
8
votes
1 answer

How to maintain a large LibraryLink project?

I have a LibraryLink project, which became more and more larger(about 50 LibraryLink wrapper functions, 8000 lines ANCI C code). Curently, I just use a simple *.c file to organize it as follows: #include " WolframLibrary.h" /*Part 0 including head…
user123
  • 385
  • 1
  • 10
7
votes
1 answer

LibraryLink: is WolframLibraryData libData persistent?

I am writing some C++ code that I want to call both through LibraryLink and independently from Mathematica. Thus it must be compatible with LibraryLink but not depend on it. When calling it from Mathematica, I want to make it abortable. All…
Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
6
votes
0 answers

A Swig-like template generator for LibraryLink

I am slowly, manually, constructing an interface to an external-API library (built in .cpp) using LibraryLink. The semi-frustrating thing is that I have a swig compatible .i file for the API that the authors have made available for generating…
flip
  • 1,800
  • 11
  • 20
6
votes
1 answer

getWSLINK documentation vs reality

The example in the documentation for getWSLINK says WSLINK link = libData->getWSLINK(libData); Compiling #include "wstp.h" #include "WolframLibrary.h" EXTERN_C DLLEXPORT int testf(WolframLibraryData libdata, mint argc, MArgument* args, MArgument…
mrupp
  • 777
  • 4
  • 9
5
votes
1 answer

How to assign pointer to a rank 2 MTensor in Mathematica C code?

I've the following code #include "WolframLibrary.h" #define bufferSize 60 EXTERN_C DLLEXPORT int getData(WolframLibraryData libData, mint Argc, MArgument*Args, MArgument Res) { mint numOfData = MArgument_getInteger(Args[0]); mint …
csk 7
  • 403
  • 2
  • 8
1
2 3 4