How do I use Embedded Matlab Coder to generate C-code?

5 visualizzazioni (ultimi 30 giorni)
I am doing embedded C-Code generation using Embedded Matlab coder. I tried the Simulink Real-Time Workshop demo:
Demos>Simulink > Real-Time Workshop > Application Samples > Embeddable C-Code Generation Using Embedded MATLAB Coder
However after running:
emlc -T rtw:exe -o rtwdemo_emlcsobel rtwdemo_emlcmain.m stdio.h
I got the error:
??? Build error: Build failed for project "main_rtw". See the target build log for further details. Error in ==> main Line: 1 Column: 1 Compilation failed: Open error report.
I am using 32-bit Matlab R2008a on a Mac.
******* BUILD LOG ********
1 gcc -c -O0 -DUSE_RTMODEL -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-common -no-cpp-precomp -fexceptions -DMODEL=rtwdemo_emlcsobel -DRT -DNUMST=1 -DTID01EQ=0 -DNCSTATES=0 -DUNIX -DMT=0 -DHAVESTDIO -I. -I/tmp/tp9376e37b_e846_409f_ba91_83b4281a6361/emlcdir -I/Applications/MATLAB_R2008a/simulink/include -I/Applications/MATLAB_R2008a/extern/include -I/tmp/tp9376e37b_e846_409f_ba91_83b4281a6361/emlcdir/emcprj/rtwexe/rtwdemo_emlcmain -I/tmp/tp9376e37b_e846_409f_ba91_83b4281a6361/emlcdir main.c
2 In file included from main.c:11:
3 main.h:13:18: error: math.h: No such file or directory
4 main.h:14:20: error: stdlib.h: No such file or directory
5 main.h:15:20: error: string.h: No such file or directory
6 In file included from /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/include/limits.h:15,
7 from rtwtypes.h:21,
8 from main.h:18,
9 from main.c:11:
10 /Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include/limits.h:15:25: error: no include path in which to search for limits.h
11 main.c:13:19: error: stdio.h: No such file or directory
12 main.c: In function 'main':
13 main.c:40: error: 'FILE' undeclared (first use in this function)
14 main.c:40: error: (Each undeclared identifier is reported only once
15 main.c:40: error: for each function it appears in.)
16 main.c:40: error: 'eml_fid' undeclared (first use in this function)
17 main.c:65: warning: incompatible implicit declaration of built-in function 'fwrite'
18 main.c: In function 'm_refp1_sqrt':
19 main.c:177: warning: incompatible implicit declaration of built-in function 'sqrt'
20 gmake: *** [main.o] Error 1
21
Could this be because I have XCode 4.0 installed? I check mex.getCompilerConfigurations() and it says it is using GNU g95. I am currently downloading XCode 3.0 to see if that helps.
----------
I tried running the same demo on a windows machine (64 bit R2010a) - I got a different error (do not have the error message) - it was something along the lines 'Could not locate MEX compiler options file mexopts.bat'. When I run mex -setup, it shows 0 compilers when I try to automatically locate a compiler. I have Visual Studio 2010 Express installed on this computer. I am currently downloading Visual Studio 2008 Express, because it looks like R2010a Simulink does not support 2010 Express (<http://www.mathworks.com/support/compilers/R2010a/win64.html)>.
Any help getting either of these issues sorted out would be appreciated.
Om
  1 Commento
Kaustubha Govind
Kaustubha Govind il 8 Lug 2013
Please paste the target build log messages for the first case (the "Open error report" message should be a link that opens up the log). For the second case, make sure that you install a supported compiler and try again.

Accedi per commentare.

Risposta accettata

Ryan Livingston
Ryan Livingston il 8 Lug 2013
If you have a look at the supported compilers for R2008a:
you will notice that XCode is necessary for using Embedded MATLAB. If you run:
mex -setup
in that MATLAB can you choose XCode as your compiler, does the code compile?
  1 Commento
Om
Om il 10 Lug 2013
I have XCode 4 installed and Matlab R2008a only supports XCode 3.0 so maybe that will solve the problem.

Accedi per commentare.

Più risposte (1)

Om
Om il 10 Lug 2013
Part 1 (Mac machine with R2008a): I noticed that XCode 4.0+ is not supported by Matlab R2008a, and I have XCode 4.4 installed on my computer. I don't want to install XCode 3.0, but I guess that could fix the problem. The emlc function is still generating C-code so it doesn't really matter at this point if Matlab is able to build it or not.
Answer to Part 2 (Windows machine with R2010a): By following http://www.mathworks.com/support/solutions/en/data/1-6IJJ3L/, I was able to use Visual Studio 2008 Express successfully with Matlab to compile mex files. In particular, I tried:
copyfile(fullfile(matlabroot,'extern','examples','mex',... 'yprime.c'), fullfile('c:','work')); Compile yprime.c.
mex yprime.c
and ran yprime(1,1:4) with the correct output.
However, when using the Embedded C-code Generator, Matlab would still fail to build. I have just given up - I don't actually need Matlab to build any of the generated C-code, since I can easily compile it outside of the Matlab environment. I just don't like seeing error messages when running a purchased toolbox.
  1 Commento
Kaustubha Govind
Kaustubha Govind il 10 Lug 2013
Om: The issue seems to be that your compiler cannot find standard libraries. What if you modify yprime.c to include stdlib.h and attempt to use a function from that library? Does it still compile with the MEX command?

Accedi per commentare.

Categorie

Scopri di più su Simulink Coder in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by