ZBrushCentral

Question:Can FileExecute run a dylib?

Is it possible for FileExecute to run a dylib (a Mac dynamic library) or is it limited to just .dll and .lib libraries?


Additional, possibly impertinent information:

When trying to load a dylib, I get the error from Zbrush that the “Specified execute-file could not be found”, while a FileExists command does find the same file.

Here is the code I’m working with:
[IButton,“Hello Button”,“This is my first button”,
[IShowActions,0]
[VarDef,Zstr,“Hello dylib!”]
[VarDef,filePath, “sampleDylib.dylib”]
[If,
[FileExists, filePath] ,
[FileExecute,filePath,MyFirstF,Zstr],
[Note, “file does not exist”]
]
,160,30
]

And the dylib is incredibly simple, and isn’t currently meant to do anything at all:

char *MessageOut = NULL;

void MyFirstF (unsigned char *message, double number, void *memblock,void *Othermemblock )
{

MessageOut = message; }

I’m running Zbrush2 on MacOSX.

Thank you kindly,
e

On the PC ZBrush will return an “Improper file name” error when trying to FileExecute a file with an extension greater or smaller than 3 characters. Perhaps try renaming the file to sampleDylib.dlb ?

Btw, the error message you posted, “Specified execute-file could not be found”, is that the exact error message? There is a similar error message that occurs when ZBrush cannot find the specified function in the dynamic link library.

I am guessing there is more to your C code than you posted, such as compiler and OS settings for creating a dynamic link library? As it stands your code is only applicable for linking at compile time and not by other programs at runtime.

That set me on a quest to learn about libraries, thank you.

Zbrush does behave differently when a dylib extension is shortened. When the file extension is changed(on the file and in the Zscript), the FileExists command cannot find the file (and it is looking at the same path) .

Essentially, it would be nice to know if I’m wasting my time trying to make a .dylib work. Based on the fact that Zbrush cannot load extensions longer than three characters, and the dylib file extension cannot be changed, the conclusion would be that Zbrush does not allow libraries developed on a Mac?

Here is the new .c in its entirety, built from Xcode: (there was also a version with #include “testbsd2.h”)

#define EXPORT attribute((visibility(“default”)))

EXPORT void ew_zfunction1(unsigned char* message, double number, void* memblock, void* memblock2)
{

}

ZBrush does already call libraries developed for a Mac so it is definitely possible. On the Mac the Zapplink plugin calls a dynamic library with the .lib extension, although I believe the extension itself is irrelevant as long as it is 3 characters in length.

Are you absolutely sure you have the correct filename in the zscript. I don’t understand how changing the extension causes FileExecute fail.

I had a quick look at the XCode manual (online) and it seems to me you should choose a Carbon or Cocoa Dynamic Library project template and work from there. Was that what you did? I am asking because I was expecting it would require more code than you show to build a dynamic library on the Mac.

I’ve recently experienced some difficulties too as I’m actually porting SizeAjustor to OSx :

So, if you’ve got an error trying to call a function in a lib with [FileExecute on OSx :


  • First, always check that the file exists with [FileExists : osX looks more regarding on paths, the right way is setting it as shown in ZFileUtils doc, something like : “ZSTARTUP_ZPLUGS/myPlugin/myLib.lib”
  • I was told that zBrush doesn’t like extensions with more than three characters, so name it blah.lib instead of blah.dylib
  • Check that you compile it for i386 architecture ( in xCode : Project menu > Set Active Architecture > i386 )
  • Check your code so that it exports the symbols you want to use correctly, with attribute(visibility(“default”)) method for instance
  • Also, do not forget extern “C” so the exported symbol have the right readable name and not something unpredictable
  • In last resort, the nm command can be useful to check the contents of your lib : just open a terminal and do “nm blah.lib”

Hope this will be useful !!! :slight_smile: