# Meson build system + C/C++ LibraryLink, help needed for portability check/fix (Windows &MacOs)

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:

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,
"Applications"}]}


which give for my computer running under Linux:

{"/home/picaud/.Mathematica/SystemFiles/LibraryResources/Linux-x86-64"}

{"/home/picaud/.Mathematica/Applications"}

where

• 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).

Questions

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.

• 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. – Rohit Namjoshi Feb 23 '19 at 23:01
• @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. – Picaud Vincent Feb 24 '19 at 5:41

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.
meson was installed by brew install meson.