Getting some more info: Mac os CPP custom operator external library linking

I’m testing out whether I can use an externally compiled .dll in a cpp custom operator, but the instructions are confusing to me Custom Operators | Derivative
If the plugin requires linking with other .dylibs or frameworks, they should be located next to the plugin.@loader_path/prefix should be used to reference the dependencies. They can be changed with the macOS toolinstall_name_tool, and the current dependency paths can be inspected with the command otool -L yourlib.dylib.
I’m using xcode and I’ve been able to successfully build the plugin based on the example CHOP CustomOperatorSamples/CHOP/BasicFilterCHOP at main · TouchDesigner/CustomOperatorSamples · GitHub. My library exposes a function called double func1() that I’m bringing in via the inclusion of the .dylib that contains the compiled library and the two header files I used.

Here I’m showing the line where I’m using the func1.

Since I’m using a dynamic library I have set the project settings to update the library search path and the runtime search path and added the @executable_path to the install name so that it will look in it’s current folder for the dynamic library files.

When I select product -> archive the build is successful and I get a window asking to distribute the contents. I select build product and it lets me select an output path for a new folder. Once I export I can go into that folder and see that the plugin has been created. According to the custom operator page I need to copy the dylib to be right there next to it so that’s the other contents in the directory.

In TD I use a customcpp operator but it shows this error when I try to load

I know that often times the paths are wrong for linking and so I decided to explore the contents of the plugin package and use otool on the executable to see where it’s trying to link my dylib.

so it thinks its supposed to find the dylib at /libtest_dylib.dylib. Unfortunate library naming aside, this isn’t where the library is so I -change the path for that. There’s a couple lines that warn me this will invalidate code signature which seems like a bad thing, but I don’t know what else to try.

TD appears to not like this invalidated code signature stuff because as soon as I try to load the plugin now, the program crashes.

So, I’m having a lot more trouble than a 1 paragraph section of the instructions seems like it covers, can anyone weigh in on how to do this fairly important task?

If it’s helpful I’m developing for an m1 mac.

Hi @humbletang - yes those instructions could be much more useful, I have just updated them (if you don’t see the updated ones, use the wiki version until the others update themselves). I’ve changed the advice to suggest using rpaths which lets you make one change in the plugin project, and one change to the library you’re linking, so one can find the other in the built plugin bundle.

If you are building a library yourself using Xcode, I’d suggest adding that Xcode project to the Xcode project for the plugin - it’s not essential but it lets you use the build product from the library in the plugin without having to manage library builds yourself. Once you’ve added the project, add the actual library to the plugin using the + symbol in the Frameworks and Libraries part of the General tab for the plugin target in Xcode - you will be able to select the library product from the top of the list that Xcode shows you - then follow the updated guidance on the wiki.

Don’t hesitate to ask if you’re not sure about anything, or if details are unclear.

Wow this is so exciting to have some more details there, sorry for delay. I’ll let you know if I get stuck. As it happens the code I’m bringing in is a header library so I’m sort of in luck that I don’t have to do the .dll route unless we get loads of copies of it running around.

Thanks all the same!

1 Like

Ok I guess I do have a question and this could totally become it’s own topic so I’ll start over here CPlusPlusCHOP Asio allowed?.

@bangnoise you seem like a much more veteran macos developer than I am so I was wondering if you had any ideas.