How Can I MEX a dynamic library (libraw) with my own C++ code on an M2 Mac?

I have existing C++ code compiled with Clang++ that uses libraw on my M2 Mac. But the dynamic libraries are arm64 and won’t work when I try to use the dynamic library with MEX. I get the following error message:
Error using mex
ld: warning: ignoring file /usr/local/lib/libraw.dylib, building for macOS-x86_64 but attempting to link with file built for
macOS-arm64
Undefined symbols for architecture x86_64:
"LibRaw::LibRaw(unsigned int)", referenced from:
MexFunction::operator()(matlab::mex::MexIORange<std::__1::__wrap_iter<matlab::data::Array*>>,
matlab::mex::MexIORange<std::__1::__wrap_iter<matlab::data::Array*>>) in rawtest4.o
and more…
I wasn’t able to figure out how to create the x86_64 libraries on my M2, so I used an Intel Mac and created the dynamic libraries on it. I then copied them to the M2 and tried again, but got this message:
ld: warning: ignoring file /Users/darral/MATLAB-Drive/libraw_darral/lib/libraw.dylib, building for macOS-x86_64 but attempting
to link with file built for unknown-unsupported file format ( 0x62 0x6F 0x6F 0x6B 0x00 0x00 0x00 0x00 0x6D 0x61 0x72 0x6B 0x00
0x00 0x00 0x00 )
Undefined symbols for architecture x86_64:
"LibRaw::LibRaw(unsigned int)", referenced from:
MexFunction::operator()(matlab::mex::MexIORange<std::__1::__wrap_iter<matlab::data::Array*>>,
matlab::mex::MexIORange<std::__1::__wrap_iter<matlab::data::Array*>>) in rawtest4.o
and more….
Can anyone advise me if there is a way to do this and how I might go about it?
Thanks

 Accepted Answer

Rik
Rik on 30 Jun 2023
Moved: Rik on 1 Jul 2023
If you're eligible for the prerelease you could give R2023b-prerelease a try, since that is native ARM.

8 Comments

Thanks,
I was going to do that but I read in the post entitled 'Why doesn't MATLAB launch after enabling new desktop mode on Mac using the R2023b prerelease?' It suggested not to install the beta because then Matlab wouldn't launch. Maybe I'm reading something wrong?
I'm going though all this because the Matlab native Imagry toolbox function rawinfo uses an old version of libraw (0.20.2), which doesn't read the data correctly for Canon CR3 files made from a Canon R3 or R6 camera. If and when this function is upgraded to the latest version of libraw it will no longer be an issue...
Also I'm running Macos 13.3.1a and R2023a on my M2 and Intel Macs.
Thanks
If I'm reading that correctly, that is only a problem if you want to use the new desktop mode. It is of course fine if you prefer using the new desktop mode, but if you don't, I don't see anything in the thread you indicated that suggests you can't use the prerelease. Or am I missing something essential?
I was just looking at some posts about the new desktop in the beta. I am comfortable with the existing desktop (in 2023a and earlier), so if I could use that it would be great. Can you clarify that I could install the M1 beta and use that desktop or would I have to run with no desktop?
Thanks again
You can install the prerelease if you're eligible. That is distinct from the beta desktop, which you would have to install separately. I understand the naming can be a bit confusing, but a prerelease is not really a beta. It is somewhere between a beta and a full release. Some changes are expected, but nothing major.
The Apple ARM CPUs are supported natively by R2023b. For older releases this was either a separate beta, or support was provided through Rosetta 2.
I hope this clarifies the situation. If not, please explain what is unclear to you.
Yes, I understand and have a current license. I'll go ahead and try to install it.
Just one more question. I'm assuming I shoud follow the instructions in https://www.mathworks.com/support/requirements/apple-silicon.html, which says to install Amazon Coretto 8 as the JRE. Are those instructions are current?
Thanks so much for your help.
Never mind. I just downloaded the silicon version, and it is clear what to do. Thanks again.
Thanks again. I installed the JRE and the 2023b pre release and the mex function successfully compiled my code and linked the dynamic libraries. This is a great solution!
You're welcome, glad to be of help

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2023a

Asked:

on 30 Jun 2023

Commented:

Rik
on 1 Jul 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!