Max SDK
repository·main·Indexed 43 days ago
https://github.com/cycling74/max-sdkHeaders, source code, and libraries for building C or C++ external objects (plug-ins) for the Max software environment. Includes CMake build configurations for Xcode and Visual Studio, guidance on configuring CMakeLists.txt for externals, and instructions for distributing DLLs and dylibs within Max Packages.
What's inside Max SDK
- For developers interested in using Modern C++ to write external objects for Max, use the Min DevKit instead of the standard C API provided in the core SDK.
Configure dylib install names on macOS for Max Packages
mainOn macOS, a dylib must be located at the exact path specified in its 'install name' for an external to load it. To avoid requiring global system directories (like
/usr/local/lib), use relative paths.Scenario 1: Single external with a bundled library
If your library is inside your
.mxobundle (e.g., in aFrameworksfolder), use@loader_pathto point to it.Bundle Structure:
myobject.mxo Contents MacOS myobject Frameworks somelibrary.frameworkLinker Flag: Set the install name to
@loader_path/../Frameworks/somelibrary.framework.Scenario 2: Multiple externals sharing a library in a Max Package
If multiple externals in a Max package need to access the same library, place the library in the package's
supportfolder. Use a relative path that traverses up from the external's location to thesupportdirectory.Linker Flag Example:
LDFLAGS += -install_name "@loader_path/../../../../support/$(NAME).dylib"LDFLAGS += -install_name "@loader_path/../../../../support/$(NAME).dylib"Install and build Max externals using CMake
mainThe Max SDK uses CMake to generate project files for Xcode (macOS) or Visual Studio (Windows). This is a required step to support modern platforms like Apple silicon.
Prerequisites
- CMake: version >= 3.25
- IDE: Xcode (macOS) or Visual Studio (Windows)
- SDK Location: Clone or download
max-sdkand place it in your Max Package folder or a directory within your Max search path.
Build Steps
Create a build directory:
mkdir build cd buildGenerate project files:
- macOS (Xcode):
cmake -G Xcode .. - Windows (Visual Studio):
cmake -G "Visual Studio 17 2022" ..
- macOS (Xcode):
Build the project: You can build via your IDE or using the command line:
cmake --build . --config Debug cmake --build . --config Release
Troubleshooting Apple Silicon Security
If you encounter a
cannot be loaded due to system security policyerror when loading your.mxoon Apple silicon, ad-hoc codesign your external:codesign --force --deep -s - myobject.mxomkdir build cd build cmake -G Xcode .. cmake --build . --config ReleaseDistribute DLLs in Max Packages using the 'support' folder
mainWhen distributing a Max external that depends on a dynamically-linked library (DLL on Windows, dylib on Mac), it is recommended to use the Max 'packages' feature.
To do this:
- Create a folder named
supportwithin your Max package folder. - Place your DLL or dylib inside this
supportfolder.
On Windows, Max automatically adds the
supportfolder to the search path for DLLs. On macOS, you must configure the library's 'install name' to point to this relative location to ensure it is found correctly.- Create a folder named
Configure a Max external's CMakeLists.txt
mainEvery Max external requires its own
CMakeLists.txtto interface with the SDK build machinery.Minimal Configuration (Automatic File Discovery)
Use
max::glob ONto automatically include all.cand.cppfiles in the directory. This is the simplest way to set up a project.set_property(DIRECTORY PROPERTY max::external YES) set_property(DIRECTORY PROPERTY max::glob ON) project(myexternal)Explicit File Configuration
If you need precise control over which files are compiled, omit
max::globand usetarget_sourcesto list files manually after theproject()call.set_property(DIRECTORY PROPERTY max::external YES) project(myexternal) target_sources(myexternal PRIVATE myexternal.cpp helper.cpp)Key CMake Properties and Commands
max::external YES: A directory property that tells the SDK to treat this directory as a Max external.max::glob ON: Automatically includes all.cand.cppfiles in the directory as source files.project(name): Names the external and triggers target creation. The resulting output will bename.mxo(macOS) orname.mxe64(Windows).- Target Customization: After the
project()command, the target named${PROJECT_NAME}is available for standard CMake commands liketarget_link_libraries,target_include_directories, andtarget_compile_definitions.
Inspect and modify dylib install names on macOS
mainIf you are using a pre-compiled third-party library, its
install_namemight not be compatible with your distribution method.Inspecting the install name
Use the
otoolcommand-line tool to find theLC_ID_DYLIBsection. This reveals the path the library expects to be found at.$ otool -l /path/to/your/library.dylibLook for the
namefield undercmd LC_ID_DYLIB.Modifying the install name
If the library's path is incorrect for your package structure, do not modify the original. Instead, copy the library and use the
install_name_toolcommand-line utility to change the path on the copy.$ otool -l /Applications/Max\ 6.1/Max.app/Contents/Frameworks/MaxAudioAPI.framework/Versions/A/MaxAudioAPI Load command 3 cmd LC_ID_DYLIB cmdsize 104 name @executable_path/../Frameworks/MaxAudioAPI.framework/Versions/A/MaxAudioAPI (offset 24)