Call .c function in working directory

Hello!
I am in way over my head trying to call a .c function in a running script.
The code is about 20 years old now and I am updating it to run on the current 2021 platform on a Mac.
Basically in this working folder I have 2 files "code.c" and "code.dll" and I amd trying to use the them in the context
z=code(x,y);
at the top of the code.c is a header:
#include <math.h>
#include "mex.h"
Ive tried simply calling the function like the following after installing code compiler:
mex code.c
Which then pops the error message of needing a compiler. I really dont want to search to find one that works with a Mac at a low storage space.
Is there any way around this?

댓글 수: 1

Walter Roberson
Walter Roberson 2021년 6월 26일
Mac does not use .dll files. Mac uses .dylib (dynamic link library) and .a (static link library) files; also dynamically loadable bundles might be .so (see https://docstore.mik.ua/orelly/unix3/mac/ch05_03.htm )

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

답변 (1개)

Jan
Jan 2021년 6월 26일
편집: Jan 2021년 6월 26일

1 개 추천

Please post a copy of the error message, not a rough paraphrasation.
"needing a compiler" seems to mean, that you did not install a compiler, which is recognized by Matlab. I guess that " current 2021 platform on a Mac" means Matlab R2021a, but what does "Mac at a low storage space" exactly mean? You need XCode 11 or 12, see: https://www.mathworks.com/support/requirements/supported-compilers.html

댓글 수: 3

Walter Roberson
Walter Roberson 2021년 6월 26일
It is likely that you could also get gcc working, with enough effort; it is not supported by MATLAB on Mac though.
Jan, Walter,
thank you both for your help! I ended up downloading xcoder for my mac (I freed up some storage space and was able to just barely fit it in). I am still getting this error message.
loadlibrary('code.dll','code.c')
gives the error message:
Error using loadlibrary
Supported compiler not found. For options, visit https://www.mathworks.com/support/compilers.
And then another command I tried:
mex code.c
gave the same exact error
Do I need to somehow initialize matlab to automatically recognize xcoder? or is there something else needed in the command.
Thank you so muh
Evan Patton
Evan Patton 2021년 6월 26일
update: all I had to do was open xcoder..... I am sorry if there was any confusion

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

카테고리

도움말 센터File Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

질문:

2021년 6월 26일

댓글:

2021년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by