33 votes

How can I work with RawArray?

This is a community wiki answer. Feel free to improve it. Introduction RawArray is an atomic array type that can hold data in any of the following formats: ...
24 votes

Which Mathematica versions have changed WolframLibraryVersion?

Run the following to find out the WolframLibraryVersion for your Mathematica, and please help complete the table below, if any entries are missing. ...
23 votes
Accepted

Fast Hankel Function in Mathematica

This is LibraryLink code with compiler and linker options specifically for macos on Apple Silicon. These are the prerequisites to compile and run this successfully: XCode installed along with the ...
Henrik Schumacher's user avatar
20 votes
Accepted

How to learn the LibraryLink technique for the newcomer?

First of all, you must be relatively comfortable with the C language. That is absolutely a prerequisite. If you are not comfortable with C, brush up your C skills first. Next, look at concrete ...
Szabolcs's user avatar
  • 235k
20 votes

Is it possible to use the DGEEV and DSYEV LAPACK subroutines in Mathematica?

You can use LibraryLink to call LAPACK directly. It involves however quite a lot of boilerplate code. Here is an example: ...
Henrik Schumacher's user avatar
19 votes

Minimal effort method for integrating C++ functions into Mathematica

In terms of loading C++ functions, I would strongly suggest LibraryLink. It is a great tool except that it requires you to write sometimes intimidating C code. To make LibraryLink easier to use, I ...
njpipeorgan's user avatar
  • 1,176
18 votes
Accepted

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

The purpose of managed library expressions is to provide "garbage collection" (i.e. automatic cleanup) for data structures created in C through LibraryLink. The documentation is here: Managed ...
Szabolcs's user avatar
  • 235k
18 votes

Why is CompilationTarget -> C slower than directly writing with C?

Using Compile with CompilationTarget->"C" does generate C-Code to be compiled in a generalized way, the resulting code will ...
Albert Retey's user avatar
  • 23.6k
16 votes
Accepted

How to debug the C code for LibraryLink?

Update: The very likely reason for the garbled error messages is that you have a Chinese version of Visual Studio printing errors in Chinese, and there is a mismatch in the character encoding of ...
Szabolcs's user avatar
  • 235k
14 votes
Accepted

C++ interface to large project

This cannot be answered very well without knowing your C++ library much better. As you said, you have a choice between MathLink and LibraryLink. Generally, I recommend LibraryLink because: It runs ...
Szabolcs's user avatar
  • 235k
14 votes

How to call the C++ by the new LibraryFunctionDeclaration?

This post is written with Mathematica version 13.1 and is subject to change in the future. Mathematica's C Types does not include vector type but includes ...
Ben Izd's user avatar
  • 9,249
13 votes
Accepted

Mathematica call C++ Eigen to calculate sparsematrix multiplication

Even if Eigen is probably not the solution for you problem at hand, it contains a couple of other interesting features that one might want to use from within Mathematica. So here a minimal example ...
Henrik Schumacher's user avatar
11 votes

Can you trigger update of Dynamic elements from a LinkedLibrary?

Preface I will give a complete solution that shows how a dynamic file watcher can be implemented in Mathematica. The file watcher will track the size of the file and when it changes automatically ...
halirutan's user avatar
  • 113k
11 votes

Can LibraryLink receive and output a list of strings?

Some time ago I wrote a post on community.wolfram.com about integrating C++ with the Wolfram Language using a library called LibraryLink Utilities (LLU). The post can be found here https://community....
rafalc's user avatar
  • 1,359
9 votes
Accepted

How to maintain a large LibraryLink project?

when I need to compile it, I used the following method: Copy the total code to Mathematica notebook with src = all_code_of_C_file, and compile it with ...
Szabolcs's user avatar
  • 235k
9 votes
Accepted

How to call the librarylink api in 13.1

You are simply misinterpreting the examples I think: Example 1: Reading the error message (please post them directly in the question in future) ...
Lukas Lang's user avatar
8 votes
Accepted

getWSLINK documentation vs reality

Use mathlink.h with LibraryLink, not wstp.h. Use the ML prefix functions, not the ...
Szabolcs's user avatar
  • 235k
8 votes
Accepted

Why does this LibraryLink function crash?

This is a incompatible pointer problem. Just change int const *dims to mint const *dims (a total of 2 places), and the function ...
vapor's user avatar
  • 7,911
8 votes
Accepted

How to call the C++ by the new LibraryFunctionDeclaration?

This is my program, in fact most of it comes from an unknown author. And it exactly is what I'm after. For more details you need to see follow this article for updates ...
yode's user avatar
  • 26.7k
8 votes

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

Don't even try that. This double indirection is not used in scientific programming because it makes it harder for the prefetcher to predict what you want. Thus it leads to higher latency and worse ...
Henrik Schumacher's user avatar
7 votes

How to debug the C code for LibraryLink?

For me (Windows 10) I get a readable error message like So I add mint saved;. Compiling again I get which leads me to change your ...
Rolf Mertig's user avatar
  • 17.2k
7 votes
Accepted

Using WSTP with LibraryLink

You will find a complete example at: $InstallationDirectory/SystemFiles/Links/LibraryLink/LibraryResources/Source/demo_LinkObject.c It's good to be aware that ...
Szabolcs's user avatar
  • 235k
7 votes

Difference between MTensor and MNumericArray in Mathematica

tl;dr Use MTensor unless you know why you need MNumericArray. Each of the LibraryLink types maps to a Mathematica type. MTensor – packed arrays (i.e. ...
Szabolcs's user avatar
  • 235k
6 votes

Why is CompilationTarget -> C slower than directly writing with C?

This is only a partial answer, but it was too long for a comment. It seems that you can slightly increase the speed of the MMA code generated for cLa, by dealing ...
jibe's user avatar
  • 852
6 votes
Accepted

Why does LibraryLink return Indeterminate sometimes?

You will see an Indeterminate in a LibraryLink array (i.e. a packed array) if it contains a NaN value ("Not a Number"). You should be extremely cautious with these ...
Szabolcs's user avatar
  • 235k
6 votes

LibraryLink: Asynchronous Examples

In Mathematica version 11.0 everything you need to know can be found in SystemFiles/Links/LibraryLink/Examples.m There, you find how you can call such a library ...
halirutan's user avatar
  • 113k
6 votes

How to prevent the kernel from exiting when a LibraryLink function segfaults?

If we all agree that bad things still might happen, then here is a start. I have set up a small repository with the code: Catching Segmentation faults in a Wolfram Library It currently works only on ...
halirutan's user avatar
  • 113k
6 votes
Accepted

Default compiler optimization flag used by LibraryLink (CreateLibrary)?

This depends on the specific compiler driver that is being used. The easiest way to get not only the compiler options, but the entire compilation command is to add ...
Szabolcs's user avatar
  • 235k
6 votes

Speedup the production of a sparse symmetric matrix with a dense vector

You don't need a library. This is already optimized in Mathematica. On my machine ...
MathematicaLover's user avatar
6 votes

How to get a MTensor variable by a vector object

Here's one way that works, although I am not sure it is the intended way: ...
Lukas Lang's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible