Call mex function using system()?

조회 수: 10 (최근 30일)
Xingwang Yong
Xingwang Yong 2021년 3월 3일
댓글: Walter Roberson 2021년 3월 3일
I downloaded a toolbox, which contains a pre-compiled mex file, foo.mexa64.
The calling syntax is a little bit confusing, but it works
system('/home/john/tools/foo.mexa64 param1 param2');
I tried to use
foo(param1, param2)
but I got an error, matlab says 'Invalid MEX-file, ...... cannot dynamically load executable'
It seems that this foo.mexa64 has been compiled to be an executable rather than a mex function. I searched the doc but it did not mention that I can build an executalbe with a suffix .mexa64.

채택된 답변

Walter Roberson
Walter Roberson 2021년 3월 3일
In Linux, executables can have any valid file name. The file extension is not considered by the operating system when deciding how to execute the code. Instead, the "magic numbers" of the file are examined.
It happens that in MacOS and Linux, shared libraries and full programs have the same structure: shared libraries just do not happen to have an entry point marked in them.
... and .mex* files are, on all operating systems, shared libraries (in a format appropriate to the operating system.)
So, Yes, even if Linux cared about file extensions, the file type for a mexa64 is the same file type as for programs. But a typical mexa64 would not define a valid entry point.
  댓글 수: 2
Xingwang Yong
Xingwang Yong 2021년 3월 3일
Thank you, Walter. Do you have any idea that how the author managed to build a mex function so that it has an entry point?
Walter Roberson
Walter Roberson 2021년 3월 3일
mex foo.c -o foo.mexa64
mex invokes standard compilation and linking processes. The output file name can be whatever you want. On MacOS and Linux the operating system doesn't care what the name is, beyond the usual restrictions that the names . and .. are reserved.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by