Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems including MATLAB "engine.h" for C++ code

I am trying to run the example code from the MATLAB Doc, but when I try to build the project in Visual Studio I get this error

fatal error C1083: Cannot open include file: 'engine.h': No such file or directory

The fact is that in the Doc I cannot find where to find the header to link it, they show the examples as if there was no need to do anything else, just do the

#include "engine.h";

Any ideas about how to solve this issue?

EDIT

I solved the first problem but now I get some errors reated to missing libs:

1>engwindemo.obj : error LNK2019: unresolved external symbol _engClose referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _mxGetClassName referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _engGetVariable referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _engOutputBuffer referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _mxDestroyArray referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _engEvalString referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _engPutVariable referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _mxGetPr referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _mxCreateDoubleMatrix_730 referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _engOpen referenced in function _main

I set the Path variable as told in the documentation, set the lib path and added some libraries and now I don't know what else can I do. I also rebooted VisualStudio in order to make the Path variable change effective.

enter image description here Thanks in advance.

like image 384
Jav_Rock Avatar asked Jan 10 '12 08:01

Jav_Rock


1 Answers

I finaly solved the problem. I was building a WIN32 project, while matlab is x64, so VisualStudio gives errors when you try to link 64-bit platforms. The solution is changing the Active Solution Platform to x64, inside Project Properties -> Configuration Manager.

It is well explained in the following link.

Thanks anyway for the answers, they were useful.

So, summarizing, to be able to compile and run a c++ code in VisualStudio2008 and Matlab2010 with engine.h, the following steps are required:

1.- Set Path variable in Advanced System Settings-> environment variables: C:\Program Files\MATLAB\R2010a\bin\win64 (or the path where libeng.dll is located)

2.- In project properties of VisualStudio, link in Additional Include directories of C++->General: "C:\Program Files\MATLAB\R2010a\extern\include"

3.- In project properties, linker->general, Additional Library Directories: "C:\Program Files\MATLAB\R2010a\extern\lib\win64\microsoft"

4.- Add the following libraries in Linker->Additional Dependencies: libeng.lib libmx.lib

5.- Change the Active Solution Platform to x64, in Configuration Manager as explained in the link.

like image 151
Jav_Rock Avatar answered Oct 05 '22 04:10

Jav_Rock