Matlab engine and C++

Forum for software developers to discuss BCI2000 software development
Locked
jpardo
Posts: 8
Joined: 23 Sep 2011, 13:35

Matlab engine and C++

Post by jpardo » 02 Dec 2011, 15:13

Hi,

I'm looking to include the matlab engine in my C++ program. Simply including engine.h does not seem to work and I keep getting an Error 1 error C2371: 'char16_t' : redefinition; different basic types on MSVC 2010.

What are the instructions to include the matlab engine appropriately? I noticed there is a MatlabWraper.h in the BCI directory, is there anyway I could use this wrapper?

Thanks,

Juan P.

jawilson
Posts: 109
Joined: 28 Feb 2005, 16:31

Re: Matlab engine and C++

Post by jawilson » 05 Dec 2011, 08:02

Definitely look into using the matlab wrapper code. I would use the src/core/SignalProcessing/Matlab code as an example. It is obviously possible to use the matlab engine without the wrapper, but the wrapper makes it much simpler, at least within BCI2000.

That said, I think your problem is due to issues between matlab and vs2010, and not BCI2000, since this issue has been reported elsewhere:
http://connect.microsoft.com/VisualStud ... b-matrix-h
Also, it looks like newer matlab versions have fixed this problem:
http://www.mathworks.com/help/techdoc/r ... ml#bs4rsll

So, if you can upgrade matlab, I would do that, or change to vs2008. Finally, you might try changing the order of your #includes, i.e., try moving engine.h before or after other #includes in your file; you are trying to change the order in which the char16_t is defined by the different files. Does that make sense?
Let me know if you have more questions.
Adam

jpardo
Posts: 8
Joined: 23 Sep 2011, 13:35

Re: Matlab engine and C++

Post by jpardo » 06 Dec 2011, 17:41

Hey Adam,

Thanks for the tip. The MatlabWrapper got me past that error and everything compiles now. However,I'm running into another problem. Every time, I run my code and the MatlabEngine::Open() is executed, the function fails to find libeng and an error "Could not load library libeng" is reported. I found a thread that discusses a similar issue (http://bci2000.org/phpbb/viewtopic.php?t=654) and suggests that 64-bit Matlab can't be used. I installed the 32-bit version as suggested by one user, but this does not seem to work for me.

How can I point my program to the libeng file? I've used the CMake instruction BCI_INCLUDE("MATLAB") to include that particular directory in extlib, but with no luck. Is there some other way to point to it?

I should mention that my C++ program isn't strictly a BCI2000 module or filter, but rather a standalone application similar to BCI2000Viewer. I'm reading BCI2000 files and then performing some basic signal analysis to display. I've included the MatlabWrapper.h and MatlabWrapper.cpp files in my project to initialize and use the Matlab Engine. I'm using 64-bit windows 7.

Thanks for your help,

Juan P.

jawilson
Posts: 109
Joined: 28 Feb 2005, 16:31

Re: Matlab engine and C++

Post by jawilson » 07 Dec 2011, 11:05

It seems like your program can't find the libeng.dll file. Try copying from your matlab directory (mine was at C:\Program Files\MATLAB\R2011a\bin\win64) to your program directory, or the program debug directory. Alternatively, you can add the matlab directory to your path.
Let me know if this works.
Adam

jpardo
Posts: 8
Joined: 23 Sep 2011, 13:35

Re: Matlab engine and C++

Post by jpardo » 08 Dec 2011, 12:09

I came up with another solution based on some stuff that I read online about Matlab R2011a. Basically, I switched my version of Matlab to 32-bit (since I'm using a 32-bit compiler), but in addition I added the directory C:\Program Files (x86)\MATLAB\R2011a\bin\win32 to my path variable by going into start menu->computer->properties-> advanced System settings->Environment Variables selecting the "path" variable and editing accordingly.

No need to copy the DLLs apparently, as long as the compiler knows what directory to look in.

Thanks for all your help!

Juan P.

Locked

Who is online

Users browsing this forum: Bing [Bot] and 1 guest