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,
"Applications"}]}
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"}
{"/home/picaud/.Mathematica/SystemFiles/LibraryResources/Linux-x86-64"}
{"/home/picaud/.Mathematica/Applications"}
where
libraryLinkIncludeDirectories
are the mma dynamic library directorieslibraryInstallDirectory
is the user directory where to install the created dynamic library (thelibXXX.so
file).packageInstallDirectory
is the user directory where to install the created package (thepackage.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.
- In my
meson.build
files I use thewolfram
command, but I am not sure it exists under Windows and MacOS, can you confirm that? (-> maybe I have to switch to thewolframscript
command). - 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.
wolfram
towolframscript
. Worked fine after that. $\endgroup$s
/...). Now this is fixed. Feel free to make an answer from your comment, I will be happy to vote it up. $\endgroup$