Static or dynamic linking in xcode for audio plugin?

I have a few third party libraries - protobuf being one of them. For years I have linked against the .dylib, and then I install that with my plugin. I use dyblibbundler to remap the path to the .dylib to its final installed location, which is Contents/Frameworks. This has worked for years.

Recently, I had a Pro Tools crash report. After sending it to Avid (because they insist on encryption), they indicated that the crash was in a Waves plugin that was calling into my protobuf dylib. I didn’t even know it was possible for another plugin to use my third party libraries (??). I use an older version of protobuf, so I’m theorizing that the Waves plugin is expecting a much later version of protobuf with some new API, and instead they get my old lib and crash on a missing API or something. As a quick fix, I have updated to the latest protobuf - this seems to help.

But, I started wondering if I should be statically linking the third party .a’s instead of using .dylib’s (?). I did a quick experiment by adding -static to my linker flags (xcode). Now all of the std c++ runtime functions don’t link, and I don’t see an option for a static runtime. Am I barking up the wrong tree?

Update for those that find this later. Mac clang++ linker prefers dynamic libs (.dylib) over static libs (.a). There is no direct way to force it to use static libs, but there are several indirect ways. The static lib can be renamed to be different from the dynamic lib. Then -L/path/to/lib and -l<unique_static_lib> can be used. That usually requires modifying the standard naming of third party libs and potentially breaking other things on your system.

I chose to avoid -L and -l altogether. In projucer, do not enter anything in “Extra Libraries to Link”. In the “Extra Linker Flags” section, simply add /path/to/lib/libsomething.a. You can add as many as you need.

The result is that you statically link your third party libs, but you do not affect the runtime linking (which occurs when you attempt to use the -static option), and I believe the runtime is necessarily dynamically linked on mac.

1 Like