필터 지우기
필터 지우기

visual studio 2010 c++ to matlab engine link errors

조회 수: 3 (최근 30일)
Etamar
Etamar 2011년 12월 19일
답변: Vijay Kumar Polimeru 2019년 4월 29일
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.

답변 (3개)

Kaustubha Govind
Kaustubha Govind 2011년 12월 19일
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.
  댓글 수: 1
Etamar
Etamar 2011년 12월 19일
Hi,
Thank you for your replay,
But what do you mean configure my project for for a win 64 not a win32?>
When I launch new project I have two options:
Win32 console application
or
Win32 Project
I understood that Win32 Project was needed for matlab GUI to use WinAPI.

댓글을 달려면 로그인하십시오.


Etamar
Etamar 2011년 12월 19일
Update:
At configuration manager in VS, I added to Platform x64, and now my link errors are different , they are:
1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol WinMain referenced in function __tmainCRTStartup 1>C:\Users\Et\Documents\Work\win32\GettingStarted\cpp2matlab\c2mdemo\x64\Debug\c2mdemo.exe : fatal error LNK1120: 1 unresolved externals
What else am i missing?
  댓글 수: 3
israel Ohiofudu
israel Ohiofudu 2013년 9월 22일
Hello,
In my case I have only the 64x runtime with Visual Studio 2012.
I have the same Link Error LNK2019.
Kaustubha Govind
Kaustubha Govind 2013년 9월 23일
israel: Is the error about WinMain or a different symbol?

댓글을 달려면 로그인하십시오.


Vijay Kumar Polimeru
Vijay Kumar Polimeru 2019년 4월 29일
Hope you have solved the problem. If not the answer written by Jav_Rock in this link may help you to debug the errors...

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by