zishun / geodesic_matlab

Exact geodesic for triangular meshes implemented by Danil Kirsanov

Home Page:https://mathworks.com/matlabcentral/fileexchange/18168-exact-geodesic-for-triangular-meshes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issues with M1 chip

weizhi-lin opened this issue · comments

Hi, thank you very much for the wonderful solutions on the geodesic distance computation toolbox. It works with windows and old macOS perfectly. However, I encountered issues with new Apple model with M1 chip. The error was:

"... (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), ..."

I would appreciate it sincerely if you can help with this issue. Many thanks!

Hi! I suppose you met the error when compiling the code. Could you provide more details like a screenshot?
I am not able to test it myself since I do not have an M1 computer. It is neither supported in Github Actions as I know.

Hi, thank you for replying! Attached please find all the information I have when compiling the codes. Thanks!

Warning Messages when compiling the codes in the terminal:

weizhilin@Tobys-MacBook-Air src % make debug
g++ -c ./geodesic_matlab_api.cpp -o ./geodesic_matlab_api.o -Wall -O2 -fPIC -DDEBUG -g
In file included from ./geodesic_matlab_api.cpp:14:
./geodesic_algorithm_subdivision.h:22:3: warning: field 'm_previous' will be initialized after field 'm_distance' [-Wreorder-ctor]
m_previous(NULL),
^~~~~~~~~~~~~~~~
m_distance(0.0)
./geodesic_algorithm_subdivision.h:29:3: warning: field 'm_previous' will be initialized after field 'm_distance' [-Wreorder-ctor]
m_previous(NULL),
^~~~~~~~~~~~~~~~
m_distance(0.0)
In file included from ./geodesic_matlab_api.cpp:15:
./geodesic_algorithm_exact.h:449:19: warning: array subscript is of type 'char' [-Wchar-subscripts]
double x = inter[i];
^~
./geodesic_algorithm_exact.h:452:14: warning: array subscript is of type 'char' [-Wchar-subscripts]
good_start[Ngood_start++] = x;
^~~~~~~~~~~~~~
./geodesic_algorithm_exact.h:455:12: warning: array subscript is of type 'char' [-Wchar-subscripts]
good_start[Ngood_start++] = right;
^~~~~~~~~~~~~~
./geodesic_algorithm_exact.h:460:27: warning: array subscript is of type 'char' [-Wchar-subscripts]
double mid = (good_start[i] + good_start[i+1])*0.5;
^~
./geodesic_algorithm_exact.h:461:10: warning: array subscript is of type 'char' [-Wchar-subscripts]
mid_map[i] = zero->signal(mid) <= one->signal(mid) ? OLD : NEW;
^~
./geodesic_algorithm_exact.h:565:16: warning: unused variable 'list' [-Wunused-variable]
list_pointer list = interval_list(edge);
^
./geodesic_matlab_api.cpp:37:1: warning: non-void function does not return a value in all control paths [-Wreturn-type]
}
^
./geodesic_matlab_api.cpp:45:14: warning: unused variable 'mesh_id' [-Wunused-variable]
std::size_t mesh_id = find_mesh_id(algorithm->mesh());
^
In file included from ./geodesic_matlab_api.cpp:14:
./geodesic_algorithm_subdivision.h:22:3: warning: field 'm_previous' will be initialized after field 'm_distance' [-Wreorder-ctor]
m_previous(NULL),
^~~~~~~~~~~~~~~
m_distance(0.0
./geodesic_algorithm_subdivision.h:102:22: note: in instantiation of function template specialization 'geodesic::SubdivisionNode::SubdivisionNode<geodesic::Vertex *>' requested here
m_nodes.push_back(Node(v)); //!!
^
./geodesic_algorithm_subdivision.h:29:3: warning: field 'm_previous' will be initialized after field 'm_distance' [-Wreorder-ctor]
m_previous(NULL),
^~~~~~~~~~~~~~~
m_distance(0.0
./geodesic_algorithm_subdivision.h:126:23: note: in instantiation of function template specialization 'geodesic::SubdivisionNode::SubdivisionNode<geodesic::Edge *, double>' requested here
m_nodes.push_back(Node(e, offset));
^
12 warnings generated.
g++ -shared -o ./geodesic_debug.so ./geodesic_matlab_api.o

Error when run example1 in the MATLAB

Error using loadlibrary
There was an error loading the library
"/Users/weizhilin/Downloads/geodesic_matlab-master/matlab/geodesic_debug.so"
dlopen(/Users/weizhilin/Downloads/geodesic_matlab-master/matlab/geodesic_debug.so,
0x0006): tried:
'/Users/weizhilin/Downloads/geodesic_matlab-master/matlab/geodesic_debug.so'
(mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')),
'/usr/local/lib/geodesic_debug.so' (no such file), '/usr/lib/geodesic_debug.so'
(no such file)

Error in geodesic_new_mesh (line 9)
loadlibrary([geodesic_library '.so'], hfile);

Error in example1 (line 13)
mesh = geodesic_new_mesh(vertices,faces); %initilize new mesh

Caused by:
Error using loaddefinedlibrary
dlopen(/Users/weizhilin/Downloads/geodesic_matlab-master/matlab/geodesic_debug.so,
0x0006): tried:
'/Users/weizhilin/Downloads/geodesic_matlab-master/matlab/geodesic_debug.so'
(mach-o file, but is an incompatible architecture (have 'arm64', need
'x86_64')), '/usr/local/lib/geodesic_debug.so' (no such file),
'/usr/lib/geodesic_debug.so' (no such file)

Looks like you have finished:

cd src
make debug
cp ./geodesic_debug.so ../matlab/

Can you try:

cd src
make example0
./example0.out hedgehog_mesh.txt 3 14

It is highly possible to be a matlab issue if example0 exits successfully.

I see. I think the problem happens inside loadlibrary. We can do nothing with the C++ code here. You may already come up with several potential solutions like

  • building the geodesic solver as a stand-alone executable and calling it with matlab.
  • using the python-binding of this implementation and calling it with matlab.
    • Even entirely shift to python to enjoy more tools from the open-source community.
  • finding out what happens inside loadlibrary.

Good luck with your work!

I was having the same problem. What happens is that when we compile on M1, we get an arm64 binary, but currently (as of 2023a), Matlab is still x86_64 (even when we install on Apple Silicon).

The workaround, therefore, is to compile in an old Intel Mac, then transfer the geodesic_debug.so file to the newer M1 Mac. I just did that and it worked. If it helps, I'm attaching the file here (gzipped; use at your own risk).

geodesic_debug.so.gz