开发者

Linking to MATLAB generated code

I'm using embedded MATLAB to generate C code from an .m script. However, after the generation I'm left with about 15 files (most of them are source). If I want to write a standalone main in C how do I link to the MA开发者_如何转开发TLAB generated code? Is there a way to do this without writing my own Makefile?


So I figured out how to generate static libraries (.a) with the matlab generated code... can I build dynamically loaded libraries (.so)?


I don't know if this is particular to my project, but I find that I can include Matlab generated files the same way as you would normally include anything else.

I copy my generated matlab source files (.c and .h) into my project directly, and then I have to specifically add them to my project. ( I wonder if that has more to do with the IDE I use though).

Then, in main.c that you create, just add the line #include "yourGeneratedFile.h". Within main.c now, you should be able to use whatever functions were created by Matlab.

For instance, in an example:

within main.c, include the header file and use the function you need

  #include "SPIUARTDemo30f.h"

//further down in the file

  SPIUARTDemo30f_step();  //using the function I asked Matlab to generate

SPIUARTDemo30f.h and SPIUARTDemo30f.c are the generated files from Matlab:

within the .h you'll see

extern void SPIUARTDemo30f_step(void);

and, if you look at the .c you'll find:

void SPIUARTDemo30f_step(void)
{
  /* lots of code */
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜