4

I'm planing to write my algorithmic codes in Matlab. And I need to convert .m files into a format where Objective-C can access. When I try mcc, the following error appeared.

The -t switch is no longer supported; the Compiler no longer generates C/C++ 
source code for M-functions (it generates wrapper functions instead, see 
the documenation for -W).

If mcc is not creating C source codes how can i generate wrappers? and do i have to copy both m file and the wrapper in order to make everything working?. And will those wrappers work in iOS??

dinesh707
  • 12,106
  • 22
  • 84
  • 134

2 Answers2

3

I'm a little confused by what you have written so I may not be answering your real question:

The Matlab documentation provides clear instructions on how to use the Matlab engine from C programs. Since Objective-C is just C with knobs on, I see no reason why you shouldn't call the engine from an Objective-C program. All that the Matlab engine will see when it is running are valid calls, it has no clue what language the calling program is written in.

I think that for your usage of mcc is irrelevant; what you need is an Objective-C compiler on your Mac. The Matlab documentation suggests that the compiler included in XCode up to v4.1 is OK for Matlab engine applications. In my experience, it may take a little fiddling with compiler options to make a more recent compiler work with your installation of Matlab, but no more than that.

If you plan to use Objective-C calling Matlab, you may not want to start by writing M-files for your algorithmic core. Actually, you probably will, but the Matlab engine doesn't really run M-files, it executes commands sent to it by an external program, such as your Objective-C program. Your development route might be (1) write M file to implement algorithm, then (2) write Objective-C program calling Matlab engine at critical steps when the Matlab functionality is required. You could write your application to make the engine run an M-file (I think) but this is outside my experience.

While you can use Matlab to run a compiler to build your programs, in this case you are probably better using XCode (or your preferred Mac IDE) to build your programs, taking care to ensure that the right linkages are made to the Matlab engine. Again, the documentation explains what you need to do.

No wrappers are involved. No M-files are required. And good luck getting the Matlab engine running on iOS !

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
3

MATLAB Compiler does not convert MATLAB code into C code, and has not done so for a long time now.

Instead, it archives and encrypts your MATLAB code and creates a wrapper (which could be an executable, a library or, if you have access also to any of the Builder products, a .NET assembly, a Java .jar file, or an Excel add-in). This wrapper dearchives and decrypts your MATLAB code, and executes it against the MATLAB Compiler Runtime, which needs to be included with your application (but is freely redistributable).

You are not going to be able to run the MCR on iOS - its footprint is just too big. If you are targeting another platform with Objective-C, you could produce a library using MATLAB Compiler and call that from your Objective-C.

MATLAB Coder (not the same as MATLAB Compiler) can convert a subset of the MATLAB language into C code. If you are targeting iOS this would be one approach, or you could alternatively run your MATLAB code remotely, and have your app access it via the web.

Sam Roberts
  • 23,951
  • 1
  • 40
  • 64