External library - FunctionNotFoundException

I have started working again on Xojo OpenCV-C, which I haven’t looked at in quite some time. I opened up the project file to find that a lot of what was in there was deprecated. All of that has now been updated.

First, I’ll say that I’ve tried this on both Windows and Mac. (The github repo only has a copy of the mac dylib so anyone testing on Windows would need to build one, or contact me and I can send a copy). This code was written in 2021 and the whole xojo project worked fine back then, except for some unfinished stuff. I’m running it now in Xojo 2023r4.

The problem I see on both platforms is that when I try to click on the LoadImage button, which calls the CVCImread function in the dll/dylib, I get a function not found exception. On my mac, this is what I see in the debugger:

Could not load CVCimread from @executable_path/../Frameworks/libOpenCVC.dylib.

I am using a build step to copy the dylib into the Frameworks folder. When I run the app, and I look inside the debug package, I can see the dylib is where it’s supposed to be, matching the path above:

/Users/perry/Desktop/XOJO_TEMP/openCVDesktop.debug.app/Contents/Frameworks/libOpenCVC.dylib

Similarly, on Windows, I see the DLL file in the App parent folder when debugging, where I have it set to go. So in both cases I know the library is where it’s expected to be, where my app is supposed to look for it.

Any ideas on what might cause this FunctionNotFound error? Could it have something to do with updating everything from the older version? Most of that was about changing the Supers on various controls and windows to the newer Desktop* versions. I get no errors when compiling, nor when I analyze the project, other than some unused variables left over from testing.

@Antonio_Rinaldi ?

It looks like the version on github was made with Xojo 2021r1.1, at least according to the warning you get if opening it on an older version. But even on 2021r1.1, it doesn’t work - same function not found exception.

That’s an old version - did it even support Apple Silicon or would that all be in Rosetta? I get no compile errors but I am on an M2 Max Mac Studio now. When this was written I was on an intel iMac

32bit/64bit mismatch?

1 Like

I’ll take a look at that tomorrow.

It wasn’t a 32/64bit mismatch. On the Mac, at least, the issue is that it was being built as a Universal application. When I changed it to x64, even though I’m running it on an M3 Max, it worked.

Presumably this means the Dylib needs to be recompiled for both x64 and arm, right?

Now to figure out what’s wrong with the Windows side.

1 Like

For Windows, you might want to double-check if the DLL matches your app’s architecture. Also, make sure the function name in your code is exactly the same as in the library. A tool like Dependency Walker can help find any missing files or mismatches.

I had this all running a couple years ago on the same PC. It’s Intel, and I’ve tried both 64 bit and 32 bit builds (Intel) - with 32bit I get an exception upon launch in the debugger. With 64bit it launches but I get the FunctionNotFoundException when trying to call a function within the DLL. I’ll need to dig a little deeper, and possibly try it out on an older version for Windows as well.

Ok. solved the Windows issue - the path to the DLL was wrong. It was set to use the Resources folder, and setting it to the app parent folder worked. Back in business!