As a proof of concept I have created a github repository that shows how to:

use the Meson build system to create a Mathematica package using LibraryLink functions

The goal is to provide an easy to use and portable solution for C/C++ projects using LibraryLink.

I have tested it under Linux for MMA version 10.0 and 11.2.

The idea is quite simple: we can have a look on how the CreateLibrary[] function works:

CreateLibrary["", "foo", 
              "ShellCommandFunction" -> Print, 
              "TargetDirectory" -> $TemporaryDirectory]

On my computer I get:

/usr/bin/gcc -shared -o "/tmp/Working-is231575-25315-2262167744-3/foo.so" -m64 -fPIC -O2 -I"/usr/local/Wolfram/Mathematica/11.2/SystemFiles/IncludeFiles/C" -I"/usr/local/Wolfram/Mathematica/11.2/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions" "/tmp/Working-is231575-25315-2262167744-3/foo.c" -L"/usr/local/Wolfram/Mathematica/11.2/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions" -L"/usr/local/Wolfram/Mathematica/11.2/SystemFiles/Libraries/Linux-x86-64" 2>&1

Nothing too surprising here: -shared -m64 -fPIC -O2 are the regular flags to create a dynamic lib, there are two include directories (-I flag) and two directories to search for mma dynamic libs (the -L flags that are forwarded to the linker)

To get the information for automatic build using Meson I process as follows:

libraryLinkIncludeDirectories = {FileNameJoin[{$InstallationDirectory,
     "SystemFiles", "IncludeFiles", "C"}], 
  FileNameJoin[{$InstallationDirectory, "SystemFiles", "Links", 
    "MathLink", "DeveloperKit", $SystemID, "CompilerAdditions"}]}
libraryInstallDirectory = {FileNameJoin[{$UserBaseDirectory, 
    "SystemFiles", "LibraryResources", $SystemID}]}
packageInstallDirectory = {FileNameJoin[{$UserBaseDirectory, 

which give for my computer running under Linux:

{"/usr/local/Wolfram/Mathematica/11.2/SystemFiles/IncludeFiles/C", "/usr/local/Wolfram/Mathematica/11.2/SystemFiles/Links/MathLink/ DeveloperKit/Linux-x86-64/CompilerAdditions"}




  • libraryLinkIncludeDirectories are the mma dynamic library directories
  • libraryInstallDirectory is the user directory where to install the created dynamic library (the libXXX.so file).
  • packageInstallDirectory is the user directory where to install the created package (the package.wl file).


I need your help because I only have access to computers under Linux and I want to check/fix the proposed approach to make it works for the Windows and MacOS OS.

  1. In my meson.build files I use the wolfram command, but I am not sure it exists under Windows and MacOS, can you confirm that? (-> maybe I have to switch to the wolframscript command).
  2. Under Windows and MacOS does the way I extract libraryLinkIncludeDirectories, libraryInstallDirectory, packageInstallDirectory makes sense/is correct??

Finally if you are interested, feel free to directly try the github repository I would be happy to accept fix/pull request.

update: now it works under Linux and MacOs. Still have no access to Windows machine so I cannot test it.

  • 2
    $\begingroup$ This is nice. On Mac OS Mojave, the only thing I had to change is what is mentioned in Question 1. wolfram to wolframscript. Worked fine after that. $\endgroup$ Feb 23, 2019 at 23:01
  • $\begingroup$ @RohitNamjoshi Thanks for the feed back! Glad to see it works under MacOS too. Also, plz pay attention that I just fixed a typo here and in the git repo: I originally forgot a 's' in a path (.../SystemFiles/LibraryResources/...). Now this is fixed. Feel free to make an answer from your comment, I will be happy to vote it up. $\endgroup$ Feb 24, 2019 at 5:41

1 Answer 1


On Mac OS Mojave and Mathematica Version 11.3, the only modification required was to change find_program('wolfram') to find_program('wolframscript') in meson.build.

Sync'd my fork with your latest commit and it worked fine without any changes.

meson was installed by brew install meson.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.