Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: engdemo.cpp

Subject: engdemo.cpp

From: Naor Movshovitz

Date: 07 Mar, 2008 16:05:04

Message: 1 of 13

The help on calling Matlab from c++ mentions this demo file
in the maltabroot/extern/examples/eng_mat, but my
installation doesn't seen to have it. Anyone know where I
can get a copy? Thanks,

-n

Subject: Re: engdemo.cpp

From: James Tursa

Date: 08 Mar, 2008 22:07:07

Message: 2 of 13

"Naor Movshovitz" <lazy_n@yahoo.com> wrote in message
<fqrp3f$kq2$1@fred.mathworks.com>...
> The help on calling Matlab from c++ mentions this demo file
> in the maltabroot/extern/examples/eng_mat, but my
> installation doesn't seen to have it. Anyone know where I
> can get a copy? Thanks,
>
> -n

I don't feel comfortable posting code from a MATLAB
installation, but you can probably find engine examples in
the FEX if you are just looking for sample code. For example
I have an engine example in submission 17660. Or if you have
questions about doing something specific I can probably
create an example for you.

James Tursa

Subject: Re: engdemo.cpp

From: lazy_n

Date: 09 Mar, 2008 12:44:56

Message: 3 of 13

On Mar 9, 12:07=A0am, "James Tursa" <aclassyguywithakno...@hotmail.com>
wrote:
> "Naor Movshovitz" <laz...@yahoo.com> wrote in message
>
> <fqrp3f$kq...@fred.mathworks.com>...
>
> > The help on calling Matlab from c++ mentions this demo file
> > in the maltabroot/extern/examples/eng_mat, but my
> > installation doesn't seen to have it. Anyone know where I
> > can get a copy? Thanks,
>
> > -n
>
> I don't feel comfortable posting code from a MATLAB
> installation, but you can probably find engine examples in
> the FEX if you are just looking for sample code. For example
> I have an engine example in submission 17660. Or if you have
> questions about doing something specific I can probably
> create an example for you.
>
> James Tursa

Thanks James,
Actually, I was just curious about what was in this example, and why
is it missing from my installation. I may have specific questions
about calling matlab from c++ later, if so I will start a new thread.
-naor

Subject: Re: engdemo.cpp

From: James Tursa

Date: 09 Mar, 2008 19:50:17

Message: 4 of 13

lazy_n <lazy_n@yahoo.com> wrote in message > Actually, I was
just curious about what was in this example, and why
> is it missing from my installation.

FYI, engdemo.c is a simple program that uses the following
functions:

engOpen
engGetVariable
engPutVariable
engEvalString
engOutputBuffer
engClose
mxCreateDoubleMatrix
mxDestroyArray

It basically does this:

- Opens the engine
- Creates local 1-dim mxArray and puts it into the engine
workspace
- Creates a plot using this variable
- Reads a string from the console and evaluates it in the
engine workspace
- Gets the result from the engine workspace to a local
mxArray variable
- Closes the engine

James Tursa


Subject: Re: engdemo.cpp

From: James Tursa

Date: 09 Mar, 2008 19:52:02

Message: 5 of 13

P.S. You can find another engine example here:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/165277

James Tursa

Subject: Re: engdemo.cpp

From: Yair Movshovitz

Date: 10 Mar, 2008 08:42:14

Message: 6 of 13

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
message <fr1f52$ba6$1@fred.mathworks.com>...
> P.S. You can find another engine example here:
>
>
http://www.mathworks.com/matlabcentral/newsreader/view_thread/165277
>
> James Tursa
>


I am having a similar problem... I can compile and run
engdemo.c (and a few simple .c files of my own) with no
problems, but I cannot get a .cpp file to be compiled.
I tried writing very simple c++ engine files, but all I get
from matlab is an error stating "not a normal file"
I searched for the engdemo.cpp file to see what is missing
in my tests but it is not where the documentation say it
should be.

Anyone knows where it is? or (even better) knows how to
compile engine programs written in c++ using matlab or an
external IDE (eclipse in my case)?

Thanks,
Yair

Subject: Re: engdemo.cpp

From: James Tursa

Date: 10 Mar, 2008 15:59:02

Message: 7 of 13

"Yair Movshovitz" <yairmov@gmail.com.remove.this> wrote in
message <fr2s95$8n7$1@fred.mathworks.com>...
> "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
> message <fr1f52$ba6$1@fred.mathworks.com>...
> > P.S. You can find another engine example here:
> >
> >
>
http://www.mathworks.com/matlabcentral/newsreader/view_thread/165277
> >
> > James Tursa
> >
>
>
> I am having a similar problem... I can compile and run
> engdemo.c (and a few simple .c files of my own) with no
> problems, but I cannot get a .cpp file to be compiled.
> I tried writing very simple c++ engine files, but all I get
> from matlab is an error stating "not a normal file"
> I searched for the engdemo.cpp file to see what is missing
> in my tests but it is not where the documentation say it
> should be.
>
> Anyone knows where it is? or (even better) knows how to
> compile engine programs written in c++ using matlab or an
> external IDE (eclipse in my case)?
>
> Thanks,
> Yair

I have had no problems compiling C++ files with MATLAB using
VC++ 8.0. Could you post an example file for me to look at?
 Which C++ compiler are you using?

James Tursa

Subject: Re: engdemo.cpp

From: Yair Movshovitz

Date: 10 Mar, 2008 17:23:02

Message: 8 of 13

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
message <fr3ls6$k8a$1@fred.mathworks.com>...
> "Yair Movshovitz" <yairmov@gmail.com.remove.this> wrote in
> message <fr2s95$8n7$1@fred.mathworks.com>...
> > "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
> > message <fr1f52$ba6$1@fred.mathworks.com>...
> > > P.S. You can find another engine example here:
> > >
> > >
> >
>
http://www.mathworks.com/matlabcentral/newsreader/view_thread/165277
> > >
> > > James Tursa
> > >
> >
> >
> > I am having a similar problem... I can compile and run
> > engdemo.c (and a few simple .c files of my own) with no
> > problems, but I cannot get a .cpp file to be compiled.
> > I tried writing very simple c++ engine files, but all I get
> > from matlab is an error stating "not a normal file"
> > I searched for the engdemo.cpp file to see what is missing
> > in my tests but it is not where the documentation say it
> > should be.
> >
> > Anyone knows where it is? or (even better) knows how to
> > compile engine programs written in c++ using matlab or an
> > external IDE (eclipse in my case)?
> >
> > Thanks,
> > Yair
>
> I have had no problems compiling C++ files with MATLAB using
> VC++ 8.0. Could you post an example file for me to look at?
> Which C++ compiler are you using?
>
> James Tursa
>

Hi James,

Thanks for trying to help.
Here is a simple function:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "/usr/local/matlab75/extern/include/engine.h"
// also tried it with only #include "engine.h"

#define BUFSIZE 256
#include <iostream>

using namespace std;

int main(){
    Engine *ep;
    
    /*
* Start the MATLAB engine locally by executing the string
* "matlab"
*/
if (!(ep = engOpen("\0"))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}

cout << "using a cpp command" << endl;
    
    /* evaluate an m file */
    engEvalString(ep, "plot(1:4, 1:4)");
    
    /*
* use fgetc() to make sure that we pause long enough to be
* able to see the plot
*/
printf("Hit return to continue\n\n");
fgetc(stdin);
    
    /* Close the matlab Engine */
    engClose(ep);
    
    return EXIT_SUCCESS;

}

I am running a linux machine (ubuntu 7.1).
I am compiling using gcc and getting the error:
mex: callingMatlabTest.cpp not a normal file or does not exist.


Thanks,
Yair



Subject: Re: engdemo.cpp

From: James Tursa

Date: 10 Mar, 2008 18:26:03

Message: 9 of 13

"Yair Movshovitz" <yairmov@gmail.com.remove.this> wrote in
message <fr3qpm$lqt$1@fred.mathworks.com>...
>
> I am running a linux machine (ubuntu 7.1).
> I am compiling using gcc and getting the error:
> mex: callingMatlabTest.cpp not a normal file or does
not exist.
>
>
> Thanks,
> Yair

Your example code compiles and runs fine, without any
modifications, using VC++ 8.0. What mex compile commands
are you using to build the exe?

James Tursa

Subject: Re: engdemo.cpp

From: James Tursa

Date: 10 Mar, 2008 18:38:02

Message: 10 of 13

> ... without any modifications...

Not quite true. I did use

#define "engine.h"

instead of your longer define for this.

James Tursa


Subject: Re: engdemo.cpp

From: Yair Movshovitz

Date: 17 Mar, 2008 08:24:06

Message: 11 of 13

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
message <fr3v6a$ii2$1@fred.mathworks.com>...
> > ... without any modifications...
>
> Not quite true. I did use
>
> #define "engine.h"
>
> instead of your longer define for this.
>
> James Tursa
>
>

Hi James,

Sorry for the long silence, I wasn't near my computer much
this last week.

I am now able to compile and run this simple function,
but when trying to run a more complicated project I get the
(run-time) error :
undefined symbol mxCreateDoubleMatrix

Thanks,
Yair

Subject: Re: engdemo.cpp

From: James Tursa

Date: 18 Mar, 2008 16:08:02

Message: 12 of 13

"Yair Movshovitz" <yairmov@gmail.com.remove.this> wrote in
message <frl9r6$7h1$1@fred.mathworks.com>...

> I am now able to compile and run this simple function,
> but when trying to run a more complicated project I get the
> (run-time) error :
> undefined symbol mxCreateDoubleMatrix
>
> Thanks,
> Yair

Do you have multiple files? mxCreateDoubleMatrix is defined
in the engine.h file.

James Tursa


Subject: Re: engdemo.cpp

From: Yair Movshovitz

Date: 19 Mar, 2008 08:43:02

Message: 13 of 13

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in
message <fropd2$dst$1@fred.mathworks.com>...
> "Yair Movshovitz" <yairmov@gmail.com.remove.this> wrote in
> message <frl9r6$7h1$1@fred.mathworks.com>...
>
> > I am now able to compile and run this simple function,
> > but when trying to run a more complicated project I get
the
> > (run-time) error :
> > undefined symbol mxCreateDoubleMatrix
> >
> > Thanks,
> > Yair
>
> Do you have multiple files? mxCreateDoubleMatrix is
defined
> in the engine.h file.
>
> James Tursa
>
>

I have 1 cpp file and it's relevant .h file.
My problem is as follows:
I need the matlab engine complier to produce a shared
library. I was unable to find a compiler flag that tells
the mex function not to produce an executable so I am
compiling with another IDE (Eclipse). The compilation
process finishes without any errors/warnings.
On run-time I get the undefined symbol mxCreateDoubleMatrix
error. I read somewhere in the Mathworks help that I need
to export a number of symbols (mexFunction etc')
but I am not sure where such a thing should be done.

Thanks,
Yair

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
cpp Yair Movshovitz 10 Mar, 2008 04:45:18
engine Yair Movshovitz 10 Mar, 2008 04:45:18
engine James Tursa 08 Mar, 2008 17:09:56
calling matab from c Naor Movshovitz 07 Mar, 2008 13:55:59
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics