Help calling .dylib on Mac OS X

I have created a .dylib with some math functions that I would like to call on a Mac. I have compiled the library as 32bit/64bit universal. I am trying to call the first function with the following code:

// extern void apm_fft_c(int64_t power_of_two, int64_t adigits, int8_t *a, double * work4, int64_t bdigits, int8_t *b, double *work5, // int8_t *r, int64_t digit_limit) Const MyDLL = "@executable_path/../libAPM.dylib" Soft Declare Sub apm_fft_c Lib MyDLL (power_of_two as int64, adigits as int64, a as ptr, work4 as ptr, bdigits as int64, _ b as ptr, work5 as ptr, result as ptr, digit_limit as int64) apm_fft_c(power_of_two, a.significant_digits, aPtr, apmfloat_work4Ptr, b.significant_digits, bPtr, apmfloat_work5Ptr, rPtr, digit_limit)

I have created a “copy files” step within the IDE to copy libAPM.dylib to the frameworks folder and verified that it is in fact there.

But I am stuck with getting the “FunctionNotFoundException”. I have tried compiling the .dylib 32 bit only, several iterations of the path with no luck. Can anyone give me some advice on how I can get past this? Thanks.

I’m not sure if this will help, but you should be declaring everything which is passed as a pointer as “byref”. So you will instead have your declare as:

Soft Declare Sub apm_fft_c Lib MyDLL (power_of_two as int64, adigits as int64, byref a as int8, byref work4 as double, bdigits as int64, byref b as int8, byref work5 as double, byref result as int8, digit_limit as int64)

I think the problem could be that the function signatures don’t match since you are using parameters with different sizes in the declare than in the actual function (hence the function not found exception). Changing everything to the correct size might help solve the problem but I’m not sure.

OK to simplify things I created a function called test in my library like this:

extern void test() {}

and call it like this:

Const MyDLL = "@executable_path/../libAPM.dylib" Soft Declare Sub test Lib MyDLL () test()

I still get a FunctionNotFoundException. I believe that I need to somehow modify the path, change how I am compiling the library or change some kind of permission but it feels like a needle in a haystack since I don’t know how to troubleshoot.

One last guess then I’m not sure what to say. In bash … means go up a directory. Following that logic, “@executable_path/…/libAPM.dylib” should bring you to “My App.app/Contents/MacOS/libAPM.dylib” which is not what you want. Does it work if you try this?

@executable_path/../../Frameworks/libAPM.dylib

Jason, unfortunately that did not work either. Searching through the forum there was one post that eluded to @executable_path but not with an example. It sure would be nice if there was a recipe in the documentation for how to build and use a .dylib file. What hurts is that I did this years ago and I can vaguely remember that one of the secrets was to declare your c function as an extern so it would be visible (which I have tried). But at this point I can’t tell if the app can’t find the .dylib or can’t find the function.

OK, I finally found the answer. I did a google search and found the blog post that had the answer.

link text

If you are building your .dylib from a C++ file (.cpp extension) then you must declare functions with

extern "C"

otherwise they won’t be exported properly and Xojo will not see them.

Yeah, C++ does this ‘mangling’ to function names. Its not just a Mac / Xcode thing.