.mltbx installer that works on multiple operating systems

3 views (last 30 days)
I am trying to create a .mltbx installer that works on multiple operating systems. The content of the .mltbx has a library that needs to be system specific (.dll for windows, .so for linux and .dylib for macos). Is there a way to have same .mltbx installer be compatible with all systems including the fact that on macos needs to be compatible with both arm and x86_64 architectures ?
If this is possible can anyone point me to how can I do that ?
My ideal result is a way to make .mltbx package to use a diffrent path to the libInterface file based on the system but I was not able to find any way to do this.
Thanks!

Accepted Answer

Rik
Rik on 12 Feb 2025

Can't you simply include all 3 files? Matlab will select the correct one automatically.

As to your point about deciding in code what you are running on: you can use the ispc() and ismac() functions. You might be able to use the computer() function to check if you're on ARM or x86_64.

  5 Comments
Muthi
Muthi on 13 Feb 2025
When generating the library interfaces I am using clibgen to generate the define file then build it and depending on system the result I get is one of the following:
  • libInterface.dll for windows
  • libInterface.so for linux
  • libInterface.dylib for both macos architectures
clibgen.generateLibraryDefinition(headers, ...
'IncludePath', includepath, ...
'Libraries', libs, ...
'PackageName', myPkg, ...
'Verbose', true)
pkg = define_myPkg;
build(pkg);
I am using mex only to specify the C++ compiler on windows and macos using
mex -setup C++
The library I am creating is an interface for is a c++ library.
In clibgen
  • "IncludePath" contains all needed ".hpp" files paths
  • "Libraries" contains a path to the library for each system ( myLib.dll, myLib.so, myLib.dylib)
Using the wrapper as you mentioned if I understand correctly would mean I would have to generate 2 diffrent .dylib files for example "myLibMacA64.dylib" and "myLibMacI64.dylib" and use the wrapper to specify the one I want to use in matlab code structures.
If that is the case this solution is not helping since the final purpose of what I am trying to do is have a .mltbx package that can be used on all systems with same function calls and no extra steps for the final user, if possible.
I am right now using multiple .mltbx packages one for each macos system.
Rik
Rik on 13 Feb 2025
The wrapper would be the function you would call instead of the compiled file. So all your other functions would still have the same syntax. Instead of including only 'myLib.dylib' you would include 'myLibMACA64.dylib" and "myLibMACI64.dylib". You would call it using wrapper() instead of myLib(), but otherwise the syntax would remain the same.

Sign in to comment.

More Answers (0)

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!