Problems including MATLAB “engine.h” for C++ code

允我心安 提交于 2019-12-04 03:07:38

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.

Have you added the MATLAB include directory to your project's include path?

. The directory should be like "C:\Program Files\MATLAB\R2010a\extern\include"

In case you forgot, add the folder containing libmat.dll libmx.dll etc. to your path. For me that was:

C:\Program Files\MATLAB\R2012a\bin\win64

While the Jav_Rock's answer is completely correct, I want to add information about one of the points:

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)

I spent three hours to understant what does it means, so I want to clarify this moment for future researchers. You need to add the path of MATLAB Engine dll libraries to your Windows. We can do it this way:

My Computer -> right click: Settings. Opened System window. Left bottom corner: Advanced System Settings

Advanced Tab

In the Environment variables for your user press Create... button and add this one: Variable name: PATH Variable value: C:\Program Files\MATLAB\R2016a\bin\win64

This path is reference on where is your libeng.dll located. Important moment: it can require to restart VS or even restart computer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!