Code Blocks configuration for Calling Matlab code from C/C++

19 ビュー (過去 30 日間)
Nathan
Nathan 2013 年 1 月 25 日
回答済み: Amir Sin 2018 年 6 月 8 日
Hey Everybody,
I was just trying to go through a simple matlab tutorial for calling matlab code from c/c++ code and Im getting an error:
code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "engine.h"
int main()
{
printf("Hello world");
Engine *ep;
ep = engOpen("");
engEvalString(ep, "x=(1:1:10);");
engEvalString(ep,"y=x.^2;");
engEvalString(ep, "plot(x,y);");
engClose(ep);
return 1;
}
Build log(Added new lines to help readability):
mingw32-gcc.exe -Wall -g -Weffc++ -std=c++0x -I"C:\Program Files\MATLAB\R2012b\extern\include" -c C:\Users\Public\Documents\C++\CToMatlab\main.c -o obj\Debug\main.o
mingw32-g++.exe -L"C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft"
-o bin\Debug\CToMatlab.exe obj\Debug\main.o
"C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libeng.lib"
"C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmat.lib"
"C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libemlrt.lib"
"C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmex.lib"
"C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmwblas.lib"
"C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmwblascompat32.lib"
"C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmwlapack.lib"
"C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmwmathutil.lib"
"C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libmx.lib"
"C:\Program Files\MATLAB\R2012b\extern\lib\win64\microsoft\libut.lib"
Error:
undefined reference to `engOpen' undefined reference to `engEvalString' undefined reference to engEvalString undefined reference to `engEvalString' undefined reference to `engClose'
I know that this is a linking error but not sure what I'm failing to link.
Any help would be apreciated.

採用された回答

Evgeny Pr
Evgeny Pr 2013 年 1 月 25 日
編集済み: Evgeny Pr 2013 年 1 月 25 日
GCC compiler for "MATLAB Externals" is not supported on windows platform. You must use the Microsoft compiler.
...but, unfortunately in CodeBlocks IDE there is a parsing command-line for Microsoft compiler bug.
I think you should use Visual Studio Express. Everything is much easier to configure. Do not forget to specify the path to the libraries and header files to MATLAB extern:
matlabroot\extern\lib\<platform>\microsoft
matlabroot\extern\include\

その他の回答 (3 件)

Nathan
Nathan 2013 年 1 月 25 日
k thanks for the help I'll probably just switch to VS now.

Tonatiuh Toral
Tonatiuh Toral 2013 年 4 月 16 日
編集済み: Tonatiuh Toral 2013 年 4 月 16 日
Hello! I'm using Code:blocks in Ubuntu 12.10 and want to call Matlab from my C++ code. I have included the matlabroot\extern\include\ in the Search directories of my Code::blocks. I tryed with the engdemo.cpp and I'm getting the same errors.
  • undefined reference to engOpen
  • undefined reference to mxCreateDoubleMatrix
  • ...
  • ...
Can anyone help me with the proper configuration for using engine.h in Code::blocks?
Kind Regards!
  1 件のコメント
Nathan
Nathan 2013 年 4 月 16 日
http://wiki.codeblocks.org/index.php?title=64Bit_Windows this should help with starting...... after that you still need to specify matlab files on the include and compiler settings.

サインインしてコメントする。


Amir Sin
Amir Sin 2018 年 6 月 8 日
Usless ans

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by