1

I used a sample code from mathworks website to integrate a MATLAB code with C/C++ by a link!

As you seen in the code, there is header file as: #include "engine.h"

In Linux (Ubuntu), I ran: g++ engdemo.cpp -o mycpp command to create an executable program, but the below fatal error occurred:

engdemo.cpp:14:20: fatal error: engine.h: No such file or directory, compilation terminated.

How can i solve this fatal error?

Amro
  • 123,847
  • 25
  • 243
  • 454
BlueBit
  • 397
  • 6
  • 22
  • Does `engine.h` file exists in the current directory? – Neigyl R. Noval Jun 06 '13 at 09:58
  • @BlueBit: you need to tell the compiler where to find the header files. You also need to link against the required libraries. The documentation explains this: http://www.mathworks.com/help/matlab/matlab_external/compiling-engine-applications-with-the-mex-command.html , http://www.mathworks.com/support/solutions/en/data/1-1BSZR/ – Amro Jun 06 '13 at 12:25

1 Answers1

2

Look in

[matlabroot '/extern/include']

If you see engine.h there, just run

g++ -I../../include engdemo.cpp -o mycpp 

(assuming you run from [matlabroot '/extern/examples/eng_mat/'])

Rody Oldenhuis
  • 37,726
  • 7
  • 50
  • 96
  • There is an error when run: g++ -I /usr/local/MATLAB/R2011b/extern/include engdemo.cpp -o mycpp : /tmp/ccNSRT82.o: In function `main': engdemo.cpp:(.text+0x4c): undefined reference to `engOpen' engdemo.cpp:(.text+0xa7): undefined reference to `mxCreateDoubleMatrix' engdemo.cpp:(.text+0xb7): undefined reference to `mxGetPr' engdemo.cpp:(.text+0x141): undefined reference to `engPutVariable' engdemo.cpp:(.text+0x155): undefined reference to `engEvalString' engdemo.cpp:(.text+0x169): undefined reference to `engEvalString' engdemo.cpp:(.text+0x17d): undefined reference to `engEvalString' ... – BlueBit Jun 06 '13 at 11:21