Matlabl Coder - Compilation Error with FILE *
이전 댓글 표시
As part of a project in which I desire to read data from a file, I use matlab's code to read a file in matlab codegen. The site found at: http://www.mathworks.com/products/matlab-coder/examples.html?file=/products/demos/shipping/coder/coderdemo_readfile.html
Has the following code:
----------------------------------------------------------------------------------------------------------------------------------------------
% y = readfile(filename)
% Read file 'filename' and return a MATLAB string with the contents
% of the file. Internally C functions fopen/fread are used to read
% data from the file.
function y = readfile(filename) %#codegen
% The 'fprintf' function will not be compiled and instead passed
% to the MATLAB runtime. If we choose to generate code for this example,
% all calls to extrinsic functions are automatically eliminated.
coder.extrinsic('fprintf');
% Put class and size constraints on function input.
assert(isa(filename, 'char'));
assert(size(filename, 1) == 1);
assert(size(filename, 2) <= 1024);
% Define a new opaque variable 'f' which will be of type 'FILE *'
% in the generated C code initially with the value NULL.
f = coder.opaque('FILE *', 'NULL');
----------------------------------------------------------------------------------------------------------------------------------------------
But I get the following error: " 'FILE' undeclared"
----------------------------------------------------------------------------------------------------------------------------------------------
gcc -c -ansi -pedantic -fwrapv -fPIC -DUSE_RTMODEL -O0 -fPIC -DMODEL=pRCBHT -DRT -DNUMST=1 -DTID01EQ=0 -DNCSTATES=0 -DUNIX -DMT=0 -DHAVESTDIO -I. -I/home/vmrguser/MATLAB/Snap\ Sensing/Online/Encoder/SideApproach/mex -I/home/vmrguser/MATLAB/R2012b/simulink/include -I/home/vmrguser/MATLAB/R2012b/extern/include -I/home/vmrguser/MATLAB/R2012b/rtw/c/src -I/home/vmrguser/MATLAB/R2012b/rtw/c/src/ext_mode/common -I. -I/home/vmrguser/MATLAB/Snap -I/home/vmrguser/MATLAB/Snap\ Sensing/Online/Encoder/SideApproach/mex/Sensing/Online/Encoder/SideApproach/matlab -I/usr/include -I/usr/include/c++/4.4 "loadData.c"
loadData.c: In function ‘loadData’:
loadData.c:97: warning: passing argument 1 of ‘atoi’ makes pointer from integer without a cast
/usr/include/stdlib.h:148: note: expected ‘const char *’ but argument is of type ‘char_T’
loadData.c:105: warning: passing argument 1 of ‘atoi’ makes pointer from integer without a cast
/usr/include/stdlib.h:148: note: expected ‘const char *’ but argument is of type ‘char_T’
gcc -c -ansi -pedantic -fwrapv -fPIC -DUSE_RTMODEL -O0 -fPIC -DMODEL=pRCBHT -DRT -DNUMST=1 -DTID01EQ=0 -DNCSTATES=0 -DUNIX -DMT=0 -DHAVESTDIO -I. -I/home/vmrguser/MATLAB/Snap\ Sensing/Online/Encoder/SideApproach/mex -I/home/vmrguser/MATLAB/R2012b/simulink/include -I/home/vmrguser/MATLAB/R2012b/extern/include -I/home/vmrguser/MATLAB/R2012b/rtw/c/src -I/home/vmrguser/MATLAB/R2012b/rtw/c/src/ext_mode/common -I. -I/home/vmrguser/MATLAB/Snap -I/home/vmrguser/MATLAB/Snap\ Sensing/Online/Encoder/SideApproach/mex/Sensing/Online/Encoder/SideApproach/matlab -I/usr/include -I/usr/include/c++/4.4 "readfile.c"
readfile.c: In function ‘b_readfile’:
readfile.c:42: error: ‘FILE’ undeclared (first use in this function)
readfile.c:42: error: (Each undeclared identifier is reported only once
readfile.c:42: error: for each function it appears in.)
readfile.c:42: error: ‘f’ undeclared (first use in this function)
readfile.c:43: warning: ISO C90 forbids mixed declarations and code
readfile.c:74: error: ‘SEEK_END’ undeclared (first use in this function)
readfile.c:83: error: ‘SEEK_SET’ undeclared (first use in this function)
readfile.c: In function ‘readfile’:
readfile.c:174: error: ‘FILE’ undeclared (first use in this function)
readfile.c:174: error: ‘f’ undeclared (first use in this function)
readfile.c:175: warning: ISO C90 forbids mixed declarations and code
readfile.c:206: error: ‘SEEK_END’ undeclared (first use in this function)
readfile.c:215: error: ‘SEEK_SET’ undeclared (first use in this function)
gmake: *** [readfile.o] Error 1
??? Build error: Build failed for project 'pRCBHT_rtw'. See the target build log in the report for further details.
----------------------------------------------------------------------- -----------------------------------------------------------------------
I have tried to include the library by typing: /usr/include/stdio.h
In Codegen's Settings for Custom Code in the "Additional Libraries and/or Additional Source Files" fields to no avail.
Any suggestions?
댓글 수: 4
Juan Rojas
2013년 2월 20일
편집: Walter Roberson
2013년 2월 20일
Vo Cong Doan
2020년 6월 16일
Please guide in detail with pictures.
Darshan Ramakant Bhat
2020년 6월 17일
You can make use of below command :
coder.cinclude("<stdio.h>");
Also please check the below example of reading a file :
Ryan Livingston
2020년 6월 18일
Many of the MATLAB file I/O functions like fopen, fread, fprintf, fscanf support code generation:
Check those out before resorting to using coder.ceval and coder.opaque
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Algorithm Design Basics에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!