having errors when compile .cc file to mex in Matlab - matlab

I am trying to complie a .cc file to mex, and I am using mex filename command in Matlab. My complier is [1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2012b\sys\lcc .
However, there are some errors:
lcc preprocessor error: learn.cc:5 Could not find include file <sys/time.h>
Error learn.cc: 70 illegal statement termination
Error learn.cc: 70 skipping `int'
Error learn.cc: 70 undeclared identifier `alen'
Error learn.cc: 71 illegal statement termination
Error learn.cc: 71 skipping `int'
Error learn.cc: 71 undeclared identifier `blen'
Error learn.cc: 87 invalid struct field declarations
Error learn.cc: 87 syntax error; found `collapsed' expecting `}'
Error learn.cc: 87 skipping `collapsed' `*' `x'
Error learn.cc: 93 unrecognized declaration
Warning learn.cc: 93 empty declaration
Error learn.cc: 97 undefined size for `incomplete struct timeval defined at learn.cc 97 tp'
Error learn.cc: 99 unknown field `tv_usec' of `incomplete struct timeval defined at learn.cc 97'
Error learn.cc: 102 syntax error; found `double' expecting `;'
Error learn.cc: 103 syntax error; found `double' expecting `;'
Error learn.cc: 106 missing parameter type
Error learn.cc: 106 syntax error; found `X' expecting `)'
Error learn.cc: 106 skipping `X' `,'
Error learn.cc: 106 syntax error; found `double' expecting `{'
Error learn.cc: 106 missing identifier
Error learn.cc: 106 too many errors
I guess the reason for the first error is that there is no time.h file in the sys folder. Instead there is timeb.h file. But I don't know the reason to the following errors.
Here are some relative codes:
line 70 int alen = **((int **)a);
line 71 int blen = **((int **)b);
line 86-93 struct data {
collapsed *x;
int num;
int numblocks;
int *blocksizes;
float *regmult;
float *learnmult;
};
line 96-100 void seed_time() {
struct timeval tp;
check(gettimeofday(&tp, NULL) == 0);
srand48((long)tp.tv_usec);
}
line 102 static inline double min(double x, double y) { return (x <= y ? x : y); }
line 103 static inline double max(double x, double y) { return (x <= y ? y : x); }
Can anyone give me a hint?

As far as i can tell, there is nothing wrong with lines 70,71. Are a,b integer double arrays declared and allocated with something like:
int ** a = malloc(4 * sizeof(int*) );
for (int var = 0; var < 4; ++var) {
a[var] = malloc(3*sizeof(int));
}
?
Are you sure that the sys/time.h file can be replaced by sys/timeb.h file? Have you tried?
sys/time.h looks like a pretty linux/unix specific file. Are you sure that the sys/ folder refers to your matlab sys directory (C:\PROGRA~1\MATLAB\R2012b\sys\lcc)?
In general, it looks like you are trying to compile a linux .mex file on a windows machine. For example gettimeofday is a linux pure call (according to this answer):
Equivalent of gettimeday() for Windows

Related

Error with show variable in data viewer for jupyter notebook

In the recent VS Code release, they added this feature to view the active variables in the Jupyter Notebook and also, view the values in the variable with Data Viewer.
However, every time I am trying to view the values in Data Viewer, VS Code is throwing error below. It says that the reason is that the object of data type is Int64 and not string, but I am sure that should not be the reason to not show the variable. Anyone facing similar issues. I tried with a simple data frame and it's working fine.
Error: Failure during variable extraction:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-16-eae5f1f55b35> in <module>
97
98 # Transform this back into a string
---> 99 print(_VSCODE_json.dumps(_VSCODE_targetVariable))
100 del _VSCODE_targetVariable
101
~/anaconda3/lib/python3.7/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
229 cls is None and indent is None and separators is None and
230 default is None and not sort_keys and not kw):
--> 231 return _default_encoder.encode(obj)
232 if cls is None:
233 cls = JSONEncoder
~/anaconda3/lib/python3.7/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)
~/anaconda3/lib/python3.7/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
~/anaconda3/lib/python3.7/json/encoder.py in default(self, o)
177
178 """
--> 179 raise TypeError(f'Object of type {o.__class__.__name__} '
180 f'is not JSON serializable')
181
TypeError: Object of type int64 is not JSON serializable

Illegal Character Escape in Text.Smolder.Renderer.String.purs

In an attempt to compile my program, I received the following error regarding the file String.purs from the Text.Smolder.Renderer module:
Error found:
at bower_components\purescript-smolder\src\Text\Smolder\Renderer\String.purs:76:
56 - 76:57 (line 76, column 56 - line 76, column 57)
Unable to parse module:
Illegal character escape code
I looked at the source file and found the following at line 76:
toStream s = foldr (\c t -> c :< (Just t)) (mkCofree '\0' Nothing) cs
How can this be corrected? (And how on earth could a compiler error be in a public library!!!)

Cannot install CVX

I try to install CVX in MATLAB but it still cannot complete. There are some error massages occurring during installation process. I have attached them already. Please see below
UNEXPECTED ERROR:
------------------------------------------------------------------------
Invalid MEX-file
'C:\Users\PAE\Downloads\Compressed\cvx-w64-tar\cvx\sdpt3\Solver\Mexfun\mexnnz.mexw64':
C:\Users\PAE\Downloads\Compressed\cvx-w64-tar\cvx\sdpt3\Solver\Mexfun\mexnnz.mexw64
is not a valid Win32 application.
.
Error in ==> checkdepconstr at 97
nnzmatold = mexnnz(AAt);
Error in ==> sqlpmain at 88
[At,b,y,indeprows,par.depconstr,feasible,par.AAt] = ...
Error in ==> sqlp at 241
[obj,X3,y,Z3,info,runhist] = ...
Error in ==> cvx_run_solver at 50
[ varargout{1:nargout} ] = sfunc( inputs{:} );
Error in ==> cvx_sdpt3>solve at 362
[ obj, xx, y, zz, info ] = cvx_run_solver( #sqlp, blk, Avec, Cvec,
b, OPTIONS, 'obj', 'x', 'y', 'z', 'info', settings, 5 ); %#ok
Error in ==> cvxprob.solve at 429
[ x, status, tprec, iters ] = shim.solve( At, b, c,
cones, quiet, prec, solv.settings, eargs{:} );
Error in ==> cvx_end at 88
solve( prob );
Error in ==> cvx_setup at 213
cvx_end
------------------------------------------------------------------------------------------
Please report this error to support, and include entire output of
CVX_SETUP in your support request.
---------------------------------------------------------------------------
I try to find the solution for this problem in GOOGLE but I cannot find it.

Compiling C++ files using MEX

I want to use MEX for compiling C\C++ files on MATLAB. I tried mex -setup first then mex xyz.cpp. But I am still getting error
E:\MATLAB~1\BIN\MEX.PL: Error: Compile of 'xyz.cpp' failed.
When typing this command
mex -v mexDiscreteFlow.cpp BPFlow.cpp Stochastic.cpp
I get the following output
This is mex, Copyright 1984-2007 The MathWorks, Inc.
-> Default options filename found in C:\Users\abc\AppData\Roaming\MathWorks\MATLAB\R2008b
----------------------------------------------------------------
-> Options file = C:\Users\abc\AppData\Roaming\MathWorks\MATLAB\R2008b\mexopts.bat
MATLAB = E:\MATLAB~1
-> COMPILER = lcc
-> Compiler flags:
COMPFLAGS = -c -Zp8 -I"E:\MATLAB~1\sys\lcc\include" -DMATLAB_MEX_FILE -noregistrylookup
OPTIMFLAGS = -DNDEBUG
DEBUGFLAGS = -g4
arguments =
Name switch = -Fo
-> Pre-linking commands =
-> LINKER = lcclnk
-> Link directives:
LINKFLAGS = -tmpdir "." -dll "E:\MATLAB~1\extern\lib\win32\lcc\mexFunction.def" -L"E:\MATLAB~1\sys\lcc\lib" -libpath "E:\MATLAB~1\extern\lib\win32\lcc" "C:\USERS\abc\APPDATA\LOCAL\TEMP\MEX_JT~1\templib2.obj"
LINKDEBUGFLAGS =
LINKFLAGSPOST = libmx.lib libmex.lib libmat.lib
Name directive = -o "mexDiscreteFlow.mexw32"
File link directive =
Lib. link directive =
Rsp file indicator = #
-> Resource Compiler = lrc -I"E:\MATLAB~1\sys\lcc\include" -noregistrylookup -fo"mexversion.res"
-> Resource Linker =
----------------------------------------------------------------
--> lcc -c -Zp8 -I"E:\MATLAB~1\sys\lcc\include" -DMATLAB_MEX_FILE -noregistrylookup -FoC:\USERS\abc\APPDATA\LOCAL\TEMP\MEX_JT~1\mexDiscreteFlow.obj -IE:\MATLAB~1\extern\include -IE:\MATLAB~1\simulink\include -DNDEBUG -DMX_COMPAT_32 C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp
lcc preprocessor error: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\ImageProcessing.h:7 C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\Image.h:7 C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp:3 Could not find include file
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 7 syntax error; found <' expecting;'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 7 skipping <'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 7 syntax error; foundT' expecting ;'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 7 syntax error; found>' expecting ;'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 7 skipping>'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 8 syntax error; found *' expecting)'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 8 skipping *'pBuffer'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 10 undeclared identifier pBuffer'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 11 undeclared identifierdelete'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 11 illegal expression
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 11 syntax error; found pBuffer' expecting]'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 11 type error: pointer expected
Warning C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 11 Statement has no effect
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 11 syntax error; found pBuffer' expecting;'
Warning C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 11 Statement has no effect
Warning C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 11 possible usage of delete before definition
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 15 syntax error; found <' expecting;'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 15 skipping <'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 15 syntax error; foundT' expecting ;'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 15 syntax error; found>' expecting ;'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 15 skipping>'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 16 syntax error; found *' expecting)'
Error C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\mexDiscreteFlow.cpp: C:\USERS\abc\DOWNLO~1\RELEASE\RELEASE\MEX\project.h: 16 too many errors
E:\MATLAB~1\BIN\MEX.PL: Error: Compile of 'mexDiscreteFlow.cpp' failed.
??? Error using ==> mex at 213
Unable to complete successfully.
Can anyone offer some suggestions ?
Thanks
lcc is the C compiler shipped with Matlab, but you are trying to compile a C++ file.
You need to run mex -setup again and choose a C++ compiler (but first get a C++ compiler, if you don't already have one)

read .yml files in matlab

I would like to read .yml files in Matlab. These files contain coordinates x and y of key points on a face image. I looked for different tools but I don't seem to find any answers.
My .yml files look like this
YAML:1.0
Image file: "00032009.jpg"
Contours count: 8
Contours:
-
Name: FO
Count: 41
Closed: 0
Points:
-
x: 682.5947265625000000
y: 743.1998901367187500
-
x: 685.9638061523437500
y: 771.3800659179687500
......
and so on
Note 00032009.jpg is an image of a face
x and y are coordinates of a point on a face Eg: the right corner of an eye etc
Could you please point out a way to read the file and then display the points on the face image?
Edit 1: Here is the error I get
Error: File: ReadYamlRaw.m Line: 14 Column: 11
Expression or statement is incorrect--possibly unbalanced (, {, or [.
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
What is weird is line 14 in ReadYamlRaw.m
[pth,~,~]= fileparts(mfilename('fullpath'));
Parse error at ','(second one) and ']' usage appears to be invalid matlab syntax.
So what is the use of ~ in there and why is there an error?
Edit2: I replaced the ~ in the line above with dummy variables then I get this errors O_O
Error using ==> ReadYamlRaw>scan at 81
Unknown data type: logical
Error in ==> ReadYamlRaw>scan_map at 138
result.(ich) = scan(r.get(java.lang.String(ich)));
Error in ==> ReadYamlRaw>scan at 79
result = scan_map(r);
Error in ==> ReadYamlRaw>scan_list at 116
result{ii} = scan(i);
Error in ==> ReadYamlRaw>scan at 77
result = scan_list(r);
Error in ==> ReadYamlRaw>scan_map at 138
result.(ich) = scan(r.get(java.lang.String(ich)));
Error in ==> ReadYamlRaw>scan at 79
result = scan_map(r);
Error in ==> ReadYamlRaw>load_yaml at 48
result = scan(yaml.load(fileread([filename, fileext])));
Error in ==> ReadYamlRaw at 19
result = load_yaml(filename, nosuchfileaction);
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
I also tried with a different yml file that looks like this
%YAML:1.0
RE-C:
x: 919
y: 580
LE-C:
x: 1209
y: 597
N-C:
x: 1063
y: 698
FO-B:
x: 1045
y: 1114
REL-O:
x: 852
y: 597
REL-I:
x: 986
y: 600
REL-T:
x: 918
y: 564
And I get the following errors
Java exception occurred:
while scanning a directive
in "<string>", line 1, column 1:
%YAML:1.0
^
expected alphabetic or numeric character, but found :(58)
in "<string>", line 1, column 6:
%YAML:1.0
^
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirectiveName(ScannerImpl.java:1028)
at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirective(ScannerImpl.java:990)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchDirective(ScannerImpl.java:534)
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:251)
at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179)
at
org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:198)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)
at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
Error in ==> ReadYamlRaw>load_yaml at 48
result = scan(yaml.load(fileread([filename, fileext])));
Error in ==> ReadYamlRaw at 19
result = load_yaml(filename, nosuchfileaction);
Error in ==> ReadYaml at 38
ry = ReadYamlRaw(filename, 0, nosuchfileaction);
Maybe someone can make something out of these or you could point out another set of functions that would work? I searched but didn't find any except this one.
It's YAML file indeed (as #DavidBrown mentioned in his comment, the extension does not matter). But it has some problems. Don't know if it's due to wrong YAML format or MATLAB implementation.
I've installed YAMLMATLAB and played a little with your file.
YamlStruct = ReadYaml(yaml_file);
YAMLMATLAB returns error if the files is feed as is. It works only if I comment the first line and remove spaces from field names. So the beginning of the file looks like this:
#YAML:1.0
Imagefile: 00032009.jpg
Contourscount: 8
...skipped the rest...
Then I get the correct structure. For example you can access the 1st point's x coordinate as
YamlStruct.Contours{1}.Points{1}.x
ans =
682.5947
UPDATE
Space in filed names is actually a known problem in YAMLMATLAB. See the report and possible solution here.
UPDATE 2
According to comment from #Jirka_cigler (YAMLMATLAB developers group):
In the program release 0.4.3 we added support for whitespaces in field
names, so the problem should not appear again.
Great!
I've also removed previous developers comment on the problem in the first UPDATE since it's not true any more.
ZozaniDB Database Toolbox comes with a Matlab-native YAML implementation that handles the .yml file here. To parse a string or a file, use:
>> yaml_parse ( str )
>> yaml_read ( filename )