Compiled Max Object fails. Reason: Image not found
After a gruelling 1.5 weeks, I finally had a Max object compiled that uses the MaxSDK and another 64-bit C++ SDK that implements functionality with an FPGA. I was using Xcode 8, and have been modifying the "collect" example that come with the SDK. My Max7 software is running at 64-bit, and I force Xcode to compile for 64-bit as well.
Last weekend, I ended up having to upgrade to macOS 10.13, and so I ended up having to download the command line tools for 10.13. In the same series of updates I also updated Xcode to 9.0.1 and my Max7 to 7.3.4. The object doesn't work in Max anymore.
The same code still compiles in Xcode as-is, but when I import the object into Max, it throws up this error in the console, and object has an orange highlight to it indicating an error:
2017-10-18 12:36:32.501 Max[42448:6844582] Error loading /Users/Aditya/Downloads/max-sdk-7.3.3/externals/collect.mxo/Contents/MacOS/collect: dlopen(/Users/Aditya/Downloads/max-sdk-7.3.3/externals/collect.mxo/Contents/MacOS/collect, 262): Library not load
ed: @rpath/Ultrahaptics.framework/Versions/2.3/Ultrahaptics
Referenced from: /Users/Aditya/Downloads/max-sdk-7.3.3/externals/collect.mxo/Contents/MacOS/collect
Reason: image not found
The error is very similar to when trying to load a 64 bit object into a 32-bit Max, but I verified that Max is still running at 64-bit, and this seems to be something to do with linking the Ultrahaptics library while building the .mxo bundle.
Interestingly, when I chuck all the code from the other SDK, the object compiles fine and loads in Max fine too.
Any guesses on where the problem might be, in this thicket of problematic variables! Any and all inputs appreciated.
Cheers!
Ok I managed to figure this one out on my own. Turns out this has nothing to do with the MacOS version at all.
This is because the framework I was using wasn't being bundled into the object I was creating, and max was trying to find it inside the /Contents/MacOS folder. This is very likely to happen especially when trying to compile a Max Object that references a 3rd party SDK/Framework/Library.
To solve this, two things need to be done:
1. The framework being used needs to be bundled into the final product: In the Xcode build phases, initialise a new "copy" phase (aka Embed binaries on older versions of Xcode). Chose Destination as Frameworks, and select the Libraries/Frameworks that need to be bundled for your application. One can right click on the compiled object and click "Show Package Contents" to make sure this happens the way it should when you build.
2. The final product needs to be told to look for the framework inside the package: In Xcode Build settings, under the linking section, find the option "Runpath Search paths". In this enter, @loader_path/../Frameworks.
Note: There are other options - @exectuble_path, @rpath, and perhaps even more and worth looking into if one doesn't work.