MEX ERRORs: Calling C++ code from MATLAB

2 次查看(过去 30 天)
mathworks2011
mathworks2011 2011-1-20
回答: HANS 2018-3-19
I am trying to run this code (GZipped Tar Ball) in MATLAB. The main.m function calls a number of C files.
I am not overly familiar with C code. I have tried to mex it, so I can run the MATLAB script, but something is going wrong.
  • I am running MATLAB 2009a on Vista. 32 bit.
  • I type mex –setup and see that I have the default MATLAB complier installed (Though I do have visual studio installed with the latest SDK)
  • Then I just type mex –fileName.c into the MATLAB command line (having cd’d to that dir). The command then fails with a whole host of error messages. EG Undeclared identifier ..., LCC pre-processor error: could not find file values.h
  • I note that the readme file contains a note saying “This C program needs some declarations in TvarTypes.h”: I don’t know what this means. Maybe it is the reason I am getting these errors?
  2 个评论
Ashish Uthama
Ashish Uthama 2011-1-20
Did you try contacting the original author? This might help: http://naranja.umh.es/~atg/blog/archives/2007/01/entry_12.html
Walter Roberson
Walter Roberson 2011-1-21
Is the software in C or is it in C++ ? If it is in C++ then LCC would not be able to compile it. Tim's answer referencing a .c file suggests that it is written in C; Petter's answer suggests that it is C that includes reference to non-standard include files.
C and C++ are different languages; it is usually easier to interface to C than to C++ .

请先登录,再进行评论。

回答(4 个)

Petter
Petter 2011-1-20
This piece of software is not written in standard C. The file "values.h" is not part of the standard. Basically whoever wrote the code did not care about portability.

mathworks2011
mathworks2011 2011-1-20
I tried replacing the values.h as suggested by Ashish. It removed one error but then more sprung up.
Petter: Unclear on what you mean. What is it written in?
The author must have had it running at somepoint! Is it not working due to being buggy or is it because of updates to visual studio/ matlab.
Really keen to get the code working: Please have a go if your a C++ person. Would be much appreciated!!!
  1 个评论
Petter
Petter 2011-1-28
I meant that it is not written in standard C. Thus, there is no reason to expect it to run on other platforms, e.g. Windows.

请先登录,再进行评论。


Tim Love
Tim Love 2011-1-21
With 2010a on linux I did
mex Pfilter.c
I got a warning about memcpy, but it was otherwise ok. I then run main from within matlab. It chugged along merrily producing graphics and lines like
time = 1080 CpxOrder = 0 RealOrder = 1, particles 100
56208886549439840066583664670207701182657741587224844696409564724083792689410710678220961942270720085773761083617378352112101243224064.000 ----------------------------------------------------------
before seg-faulting. It's rather old C code, and memcpy usage might need tightening up, but it's not completely broken.

HANS
HANS 2018-3-19
Hi to all :)
I have name.mex function and many .cpp and .h files related to it. name.mex takes only 1xinf vector which is a complex double values inside and output is the same size vector.
I want to call this name.mex within C++. As I know I have to use "int mexCallMATLAB(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[], const char *command_name);"
Please could anybody give a usage example in C++ ? I guess I have to use "ifstream" to load the data vector before I use the function but do I have to define via "mxArray" or ??
Thx, WR

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by