views:

279

answers:

2

I'm writing a Java application that needs to be able to run MATLAB commands. To do so, I'm using a C program that the Java application can call upon to interface with MATLAB. However, even after researching the MATLAB engine, I can't seem to figure out how to compile the C program. This documentation seems to be compiling the C program from within MATLAB: http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f39903.html. Is there any way to compile from the command line? That is, can I use gcc with some flags to include all the relevant MATLAB support (I don't ordinarily program in C, so sorry if my language is not exactly correct!)

Thanks!

A: 

I don't use MATLAB, but I'm guessing that you have to do something like this:

  1. Compile your C program with MATLAB libraries to create a shared library that Java can use.
  2. Write a JNI interface that calls your shared library, being sure to link in your new SO and all those from MATLAB that you need.

Break the problem into steps and you'll sort it out.

duffymo
I think that what I'd like to do is have an executable C program. My Java application can then call on this C program and pass in arguments through the command line. So I need help with step (1), the actual compilation of C into executable.
Stephen Poletto
A: 

Maybe you want do the following :

1) Compile your matlab code (i.e m files ) with the matlab compiler mcc from the matlab command line. mcc compiler generates c dll . The matlab generated c dll contains the c interface for the matlab m files. See the following link about how to generate c dll from matlab M files. C Shared Library Target

2) Write c dll that uses the generated matlab dll in step 1. Compile the c dll with c compiler.See the following link about how to call the functions that are inside the matlab generated dll MATLAB Compiler Generated Interface Functions

3) Use the generated c dll in step 2 with java.

if you want to use standalone c exe instead c dll see the following link http://www.mathworks.com/access/helpdesk/help/toolbox/compiler/f7-996249.html
Thanks for the links! I'll try this method and see if I run into any problems. Thanks!
Stephen Poletto