visual studio 2010 c++ to matlab engine link errors
4 views (last 30 days)
Show older comments
Hi All,
I'd appreciate some help here, getting kinda frustrated after googling and troubleshooting my problem here.
I am trying to run an example that communicates to matlab via matlab engine from c++ but continually encounter errors. Here is what i'm doing step by step:
1.launch vs2010. New project , Win32 project (i understood because of matlab GUI i need win32 and not console),empty project.
2.New source file with this code:
#include<iostream>
#include<cmath>
#ifdef _CHAR16T //redifined definition problem
#define CHAR16_T
#endif
#include "engine.h"
using namespace std;
int main(){
Engine *ep = engOpen(NULL);
double x[1000];
double y[1000];
double z[1000];
double t = 0;
const double dt = 0.001;
int i,j;
double a,b;
mxArray *z_array = mxCreateDoubleMatrix(1000,1,mxREAL);
mxArray *a_array = mxCreateDoubleMatrix( 1,1,mxREAL);
mxArray *b_array = mxCreateDoubleMatrix( 1,1,mxREAL);
double *pz = mxGetPr(z_array);
double *pa = mxGetPr(a_array);
double *pb = mxGetPr(b_array);
for (i=0;i<1000;i++){
x[i] = cos(2*3.14*t);
y[i] = sin(2*3.14*t);
t+=dt;
}
a = 1;
b = 0;
for (j=0;j<100;j++){
for(i=0;i<1000;i++){
z[i] = a*x[i] + b*y[i];
pz[i] = z[i];
}
pa[0] = a;
pb[0] = b;
engPutVariable(ep,"z",z_array);
engPutVariable(ep,"a",a_array);
engPutVariable(ep,"b",b_array);
// engEvalString(ep,"testPlot");
a = a - 0.01;
b = b + 0.01;
}
engClose(ep);
return 0;
}
3.Add header file engine.h from C:\Program Files\MATLAB\R2010a\extern\include
4.Configure project properties: a. C/C++ \ General \ Additional Include directories: C:\Program Files\MATLAB\R2010a\extern\include b. Linker \ General \ Additional Library Directories: C:\Program Files\MATLAB\R2010a\extern\lib\win64\microsoft c.Linker \ Input \ Additional Dependencies : libeng.lib libmat.lib libmex.lib libmx.lib
The compiler error I receive are:
1>maindemo.obj : error LNK2019: unresolved external symbol engClose referenced in function _main 1>maindemo.obj : error LNK2019: unresolved external symbol _engPutVariable referenced in function _main 1>maindemo.obj : error LNK2019: unresolved external symbol _mxGetPr referenced in function _main 1>maindemo.obj : error LNK2019: unresolved external symbol _mxCreateDoubleMatrix_730 referenced in function _main 1>maindemo.obj : error LNK2019: unresolved external symbol _engOpen referenced in function _main 1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function __tmainCRTStartup 1>C:\Users\Et\Documents\Work\win32\GettingStarted\cpp2matlab\c2mdemo\Debug\c2mdemo.exe : fatal error LNK1120: 6 unresolved externals
More Info:
I am running windows 7 64. Matlab 2010a. Visual studio 2010.
My Environmental variables have PATH with: C:\Program Files\MATLAB\R2010a\runtime\win64; C:\Program Files\MATLAB\R2010a\bin; C:\Program Files\MATLAB\R2010a\bin\win64;
Ofcourse if more information is needed just let me know, I am not a computer engineer , or programmer by education , so pls be gentle with me ;). Anyway , as said before Id really appreciate any help on this issue.... tx, Etamar.
0 Comments
Answers (3)
Kaustubha Govind
on 19 Dec 2011
If you are using 64-bit MATLAB, all the libraries in C:\Program Files\MATLAB\R2010a\extern\lib\win64\microsoft are also 64-bit binaries. Therefore, you need to configure your Visual Studio project for a win64 application, not win32.
Etamar
on 19 Dec 2011
3 Comments
israel Ohiofudu
on 22 Sep 2013
Hello,
In my case I have only the 64x runtime with Visual Studio 2012.
I have the same Link Error LNK2019.
Vijay Kumar Polimeru
on 29 Apr 2019
Hope you have solved the problem. If not the answer written by Jav_Rock in this link may help you to debug the errors...
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!