Questions tagged [librarylink]

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

Filter by
Sorted by
Tagged with
111
votes
6answers
11k views

Minimal effort method for integrating C++ functions into Mathematica

Update: While at the time of writing the question loading DLLs with .NET/Link seemed easier, now I always use LibraryLink, which I recommend to anyone with a similar problem! As of Mathematica 8, ...
73
votes
1answer
2k views

How to simplify writing LibraryLink code?

LibraryLink is an API for extending Mathematica through C or C++. It is very fast because it gives direct access to Mathematica's packed array data structure, without even needing to make a copy of ...
42
votes
1answer
3k views

Linking FORTRAN with Librarylink

FORTRAN code can be called using MathLink or .NET/Link (see the link for a worked examples). But as mentioned in a talk by T.Gayley and J.Klein in Wolfram Technology Conference 2011, LibraryLink, ...
33
votes
1answer
1k views

How can I work with RawArray?

RawArray seems to be able to efficiently hold integer and floating point data of various sizes. What is RawArray good for? How ...
30
votes
2answers
614 views

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

Probably a hard question, but I think it's better to cry out loud. I've hesitated for a while about whether I should post this in StackOverflow with a c tag or not,...
28
votes
4answers
7k views

Efficiently determining if 3D points are within a surface composed of polygons

This is the 2nd part of a previous question which I edited to make into 2 separate questions: Extracting polygons from 3D contour plot surface As an extension of my earlier question involving simple ...
26
votes
1answer
844 views

Asynchronous Programming

Consider that you would like to listen for Raw WiFi Packets coming into your NIC. Since Mathematica doesn't have built-in functions for such low level programming (as far as I know), one alternative ...
25
votes
6answers
861 views

Returning multiple results from a LibraryLink function

What is the best way to return multiple inhomogeneous results from a LibraryLink function? Imagine that the result of a single computation is several tensors of different dimensions and several ...
23
votes
0answers
475 views

LibraryLink: What can we do with MInputStream and MOutputStream?

Version 9 introduced the WolframStreamsLibrary.h header for LibraryLink. It contains MInputStream and ...
18
votes
1answer
501 views

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)...
18
votes
1answer
441 views

MathLink (WSTP) vs LibraryLink performance

Has anyone benchmarked LibraryLink vs MathLink when passing large arrays? Specifically I would like to know how performance compares when using the following to pass and return a large array: ...
17
votes
1answer
356 views

Dynamic and LibraryLink: dynamic visualization of a simulation

I am asking this question to save some time and I am expecting answers only from people who have tried something like this before. (I realize that I could just try it and see if it works, but that ...
16
votes
2answers
552 views

Using Boost with CreateLibrary

I was looking at the answer of Leonid of Faster alternatives for DayOfWeek and wanted to see how hard it would be to do something similar in C++ using an external library like Boost. I tried to ...
16
votes
1answer
1k views

C++ interface to large project

We are developing a quite large mathematical software in C++ and would like to have a Mathematica interface. We have our own C++ library and our idea would be, to write a Mathematica wrapper class and ...
16
votes
1answer
828 views

How to use MKL from Mathematica?

MKL has a lot of functions. The question is: how to use these functions directly from Mathematica? Furthermore, Mathematica shipped with some MKL libraries, which is located in $...
15
votes
1answer
383 views

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

I do realize that this might be controversial, but I believe I have a real need for it this time. If a process tries to access memory at a location it doesn't own, it will by default exit with a "...
14
votes
2answers
343 views

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 ...
14
votes
2answers
338 views

How to properly generate messages from LibraryLink function?

I'm currently using WolframLibraryData::Message to generate messages from a library function, like this: ...
13
votes
1answer
505 views

How to use RunProcess to import external function?

I have a functions written in an external language called GO. How can I quickly load them into the kernel for use as Mathematica functions? The two ways I've tried are with MathLink and LibraryLink ...
13
votes
2answers
1k views

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 ...
13
votes
1answer
256 views

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 ...
13
votes
1answer
120 views

How to service preemptive computations while running a LibraryLink function?

Cross-posted to Wolfram Community The following is from the comparison between WSTP (MathLink) and LibraryLink in the documentation: When the Wolfram Language is waiting for a WSTP application to ...
12
votes
1answer
813 views

Mathematica + Numerical Recipes

the idea of combining Mathematica with the new routines in the 3rd edition of Numerical Recipes (NR) is very interesting. In fact, there is a NR library to Matlab which works very well because not ...
12
votes
1answer
192 views

Is it possible for LibraryLink function to be Listable like that in Compile?

We know in Compile, there is an Option RuntimeAttributes -> {Listable} which can let the compiled function easily explore the ...
12
votes
1answer
335 views

LibraryLink Documentation

Bug fixed in version 10.0.0 The documentation for LibraryLink has the following example ...
12
votes
1answer
486 views

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 ...
11
votes
3answers
769 views

How to debug the C code for LibraryLink?

Recently, I use the C to rewrite a Mathematica function NonzeroBasis[], please see here for fully descriptions. Here, ...
11
votes
1answer
1k views

How to use C language functions in Mathematica? [duplicate]

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: ...
11
votes
1answer
309 views

Where is my memory? — LibraryLink never returns the memory

Bug introduced in 8.0 or earlier and persisting through 10.3 This is an example LibaryLink code from Mathematica documentation, which takes an integer and return an integer list: ...
11
votes
1answer
791 views

How to load FORTRAN libraries through Librarylink

First, the main reference is the thread Linking FORTRAN with Librarylink, which teaches how to make the link between a FORTRAN subroutine and a Mathematica code, by using Librarylink. This must done ...
11
votes
2answers
433 views

Why LibraryLink function crashes at a second time?

Bug introduced in 9.0 or earlier and fixed in 10.3 Update As Todd Gayley commented under halirutan's answer, this is a bug. I'm trying link one of Lapack's function to Mathematica through ...
11
votes
2answers
659 views

Converting other C++ classes to MTensor in LibraryLink

Hopefully this will be a quick question + a quick answer: Say I have a C++ (or C) code using LibraryLink. I am using a library that defines a specific matrix class, as many numerical libraries ...
10
votes
1answer
271 views

LibraryLink: Asynchronous Examples

Inside the directory structure of LibraryLink there are several example files. Basically, they are divided in two types: Synchronous: demo.c, demo_error.c, ...
10
votes
1answer
333 views

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 ...
10
votes
0answers
102 views

LibraryLink: How to read from a Mathematica stream in C?

Mathematica has a flexible streams interface. Functions like Read can read from a "stream" that may be backed by a file, pipe, string, network resource, etc. We can ...
10
votes
0answers
113 views

Compile M11.1-compatible LibraryLink libraries using M11.2

WolframLibraryVersion, defined in WolframLibrary.h, was bumped from 3 to 4 in Mathematica 11.2. This causes libraries compiled ...
9
votes
2answers
204 views

Why does this LibraryLink example of LinkObject based passing not work? Bug or user error?

There's an example of LinkObject-based passing in the LibraryLink documentation. Unfortunately the cell in the documentation notebook is corrupted, but to skip ...
9
votes
1answer
303 views

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 ...
9
votes
1answer
147 views

How to cross-compile LibraryLink code for multi-platform distribution

I am running Mathematica on a Windows 10 machine and I would like to develop a package for public distribution. Most of the package will be Mathematica code, but some timing-critical parts should be ...
8
votes
2answers
1k views

Mathematica Library Link : How to use non standard 'mint' e.g. 'unsigned int' or 'long long int'

I use Mathematica 8.0.4 on Mac OSX 64 bit, and gcc as C compiler. I am trying to write a LibraryLink function that deals with large positive integers i.e. greater than $2^{31}-1$. By dealing with, I ...
8
votes
1answer
189 views

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 ...
8
votes
1answer
377 views

Type conversion: LibraryLink mint vs. MathLink integer type

Assume the following situation: I have a WolframLibrary function which gets as parameter an integer tensor (which is for simplicity of rank 1) and the function should return an integer list through ...
8
votes
1answer
253 views

How to use MacPorts' gcc with CreateLibrary?

Short version: What's the simplest way to use MacPorts' gcc with CreateLibrary? Long version: CreateLibrary uses ...
7
votes
2answers
1k views

How to convert data types in a LibraryLink wrapper

I have a dynamic library which I want to load into Mathematica using LibraryLink. I don't have access to the source code of the library, so I need a C wrapper to do the job. In the C wrapper, I would ...
7
votes
2answers
160 views

Is it possible to attach a debugger to a dynamically linked library on the supported OS?

Recently, I discovered that LibraryLink technique is a very useful tool to improve the performance of function. Firstly, I need to use LibraryLink template to write C/C++ program. Then compiling the ...
7
votes
2answers
981 views

How can I integrate Open-CV with Mathematica?

I would like to run Open-CV functions from within Mathematica, can anyone figure out how to do this?
7
votes
1answer
192 views

LibraryUnload fails

I can load my library, but I cannot unload it with LibraryUnload. I do have a ...
7
votes
1answer
207 views

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 ...
7
votes
0answers
81 views

LibraryLink: Create SparseArray directly from row pointers and column indices

In Mathematica, sparse arrays use a CSR representation. Suppose I already have data in this format. Is there a way to create an MSparseArray from it directly with ...
7
votes
0answers
105 views

LibraryLink: What are DataStore and WolframIOLibrary?

Version 9 introduced DataStore and WolframIOLibrary_Functions in WolframLibrary.h. They don'...