# 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 some cases, the performance/efficiency of user-defined is very critical. For instance, I have been learning the NURBS theory for two years with the help of the classical textbook "The NURBS Book" written by Les Piegl and Wayne Tiller. In this process, I also developed a package CAGD via the pure Wolfram Language.

About the performance turning of some functions that in my package, I believe Compile[] and CompilationTarget -> "C" are very useful tricks, here is an example that using Compile[] and CompilationTarget -> "C":

Nevertheless, when I added the option SplineWeights in CAGDBSplineFunction[], its performance was much slower(about $10$ times) than built-in BSplineFunction[], please see the below screenshots:

Here, BSplineFunction[] was a compiled version to C code. In addition, I'm not surprised at the high performance of built-in BSplineFunction[] because I know it was implemented in low level language(maybe C++/C) rather than its own Wolfram Language.

### Learning about LibraryLink

To improve the performace/efficiency of my packege CAGD, I recently decided to rewrite some critical/key functions in C, then I would like to utilize the Library Link technique to link the C code to Mathematica.

Firstly, I read the documentation about the that technique via Wolfram LibraryLink User Guide, however, I discovered that it was not a easy thing to learn that tutorial. For me, I only learned C and Visual Basic when I was a freshman seven years ago.

### Question

• Is there some simple mehtods to learn the Library Link for the newcomer?

• What other knowledge(about the computuer language) need to be learned?

## 1 Answer

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 examples while reading the LibraryLink user guide. The examples are described in the last section. Start with the simplest ones. The user guide is meant more as a complete description of all LibraryLink features rather than a tutorial. It's going to be easier to start with a tutorial instead. Luckily Arnoud has written up a very nice series of detailed tutorials for getting started with LibraryLink.

Work through these in order. There may be some posts I missed, so this table of contents may not be complete. Update: Here's the official table of contents with additional links.

If you find these too basic or two slow, take a look at an answer he wrote on this site:

It uses plain C, not C++, so don't be discouraged by the title.

Regarding the thread you linked (How to simplify writing LibraryLink code?), I do not recommend that you use LTemplate before you are comfortable with plain LibraryLink. It is meant to make day-to-day work with LibraryLink easy once you already know how to use it. It won't be easier to learn LibraryLink with it (quite the opposite). At this moment it is not meant for beginners. Someday I'll try to write up a basic tutorial for LTemplate too, but we're not there yet.