Hi,

as promised in my precedent post, here is my new question. I would like to import data from a matfile into BCI2000. For this purpose I use the matlab extlib provided with BCI2000. I thus included in the CMakeList corresponding to my module the following line:

BCI2000_USE( "MATLAB" )

It helped me to get rid of compilation errors but I still have the following linkage errors:

Linking CXX executable C:\Coding\BCI2000\prog\EmoPlaySignalProcessing.exe

CMakeFiles\EmoPlaySignalProcessing.dir/objects.a(EmoPlayFilter.cpp.obj):EmoPlayFilter.cpp:(.text+0x4b): undefined reference to `matOpen'

CMakeFiles\EmoPlaySignalProcessing.dir/objects.a(EmoPlayFilter.cpp.obj):EmoPlayFilter.cpp:(.text+0x65): undefined reference to `matGetVariable'

CMakeFiles\EmoPlaySignalProcessing.dir/objects.a(EmoPlayFilter.cpp.obj):EmoPlayFilter.cpp:(.text+0x8d): undefined reference to `matClose'

collect2: ld returned 1 exit status

Are the lib present in the matlab directory only compiled for Borland ?

I am using mingw32 in association with CodeBlocks under windows 7 and with BCI2000 V3.0.

Also I do not know if this is related but I got that message when trying to use the matlab signal processing module:

MatlabFilter::Constructor: Could not load library libeng

Guillaume

------ Some things I did so far

Here are a few things that solved the situation but I would like your opinion on it and especially how to make it nicer.

1. change the matlab lib files that are in the extlib/matlab folder by those in my own matlab folder compiled with ld (the BCI2000 files where not recognized by mingw32),

2. rename the files "libxxx.lib" in the extlib/matlab folder to "xxx.lib" since for some reason all the lib annotations are removed by the cmake compilation (this one took me a long time to find),

3. change the cmake/extlib/Matlab.cmake file to include:

# Define the library directory

SET( LIBDIR_EXTLIB_MATLAB ${BCI2000_SRC_DIR}/extlib/matlab )

# Set the name of the library to link against within LIBDIR

SET( LIBS_EXTLIB_MATLAB mat.lib )

4. change the cmake/SetupExtLibDependencies.cmake to add at the proper position:

LINK_DIRECTORIES( ${LIBDIR_EXTLIB_MATLAB} )

SET( ${LIBRARIES}

${${LIBRARIES}}

${LIBS_EXTLIB_MATLAB}

)

that worked and I guess that some other needed lib can be added in the same way. I did not tried to recompile the whole BCI2000 to check if the "MatlabFilter::Constructor: Could not load library libeng" error disapears (if I add the libeng lib of course).

Please any comments are welcome or other / better solutions !

## Matlab external lib and mat functions

### Re: Matlab external lib and mat functions

Guillaume,

the BCI2000 Matlab Signal Processing does not link to the .lib files from the extlib/Matlab directory. Rather, there is a library wrapper file at src/core/SignalProcessing/Matlab/MatlabWrapper.cpp that loads required DLLs using LoadLibrary() from the Windows API. The "Could not load library libeng" error message means that the Matlab DLLs are not available from the Windows path. It appears that more recent Matlab versions do not add their DLL directory to the Windows path any more, so you need to do that manually.

What you did was the right thing to do when linking against Matlab .lib files, but this won't work with the Matlab Signal Processing module any more. What you could have done would have been to include src/core/SignalProcessing/Matlab/MatlabWrapper.cpp into your target.

Regards,

Juergen

the BCI2000 Matlab Signal Processing does not link to the .lib files from the extlib/Matlab directory. Rather, there is a library wrapper file at src/core/SignalProcessing/Matlab/MatlabWrapper.cpp that loads required DLLs using LoadLibrary() from the Windows API. The "Could not load library libeng" error message means that the Matlab DLLs are not available from the Windows path. It appears that more recent Matlab versions do not add their DLL directory to the Windows path any more, so you need to do that manually.

What you did was the right thing to do when linking against Matlab .lib files, but this won't work with the Matlab Signal Processing module any more. What you could have done would have been to include src/core/SignalProcessing/Matlab/MatlabWrapper.cpp into your target.

Just out of curiosity: How did you create those lib files?change the matlab lib files that are in the extlib/matlab folder by those in my own matlab folder compiled with ld (the BCI2000 files where not recognized by mingw32),

Regards,

Juergen

### Re: Matlab external lib and mat functions

Thanks for your answer,

I went back from what I did (which did not work in the end) and including the matlab libs in the path did solve the problem for the matlab signal processing module.

I also tried to include the matlabwrapper in my module and I am trying to use it. As I understood so far I should open a Matlab engine, invoke my matlab functions and then close the engine. However I would like to avoid the engine to be able to load a mat file without having the complete matlab environement installed. Is there a way to call the functions matOpen, matGetvariable, matClose without opening a matlab engine? I saw that many functions of the matlab wrapper are static and I hope that this could help with this issue.

To answer your question: I did not compile any library, I just replaced the matlab lib files provided by BCI2000 by those of my matlab (available in $MATLABDIR/extern/lib/win32/lcc) or you could also use the microsoft ones: $MATLABDIR/extern/lib/win32/microsoft. If I could have compiled the libs I think I would just have included the sources in my BCI module

Guillaume

I went back from what I did (which did not work in the end) and including the matlab libs in the path did solve the problem for the matlab signal processing module.

I also tried to include the matlabwrapper in my module and I am trying to use it. As I understood so far I should open a Matlab engine, invoke my matlab functions and then close the engine. However I would like to avoid the engine to be able to load a mat file without having the complete matlab environement installed. Is there a way to call the functions matOpen, matGetvariable, matClose without opening a matlab engine? I saw that many functions of the matlab wrapper are static and I hope that this could help with this issue.

To answer your question: I did not compile any library, I just replaced the matlab lib files provided by BCI2000 by those of my matlab (available in $MATLABDIR/extern/lib/win32/lcc) or you could also use the microsoft ones: $MATLABDIR/extern/lib/win32/microsoft. If I could have compiled the libs I think I would just have included the sources in my BCI module

Guillaume

### Re: Matlab external lib and mat functions

Guillaume,

matOpen etc. functions are in the libmat library, which is not loaded by the MatlabWrapper.

Sorry for the misunderstanding.

Juergen

matOpen etc. functions are in the libmat library, which is not loaded by the MatlabWrapper.

Sorry for the misunderstanding.

The libs contain DLL loading code, and can sometimes be converted from one compiler's format to another's. I was hoping to learn about how to create MinGW-compatible import libraries from MSVC ones.If I could have compiled the libs I think I would just have included the sources in my BCI module

Juergen

### Re: Matlab external lib and mat functions

What a pity...

I am not sure I understand what you meant by your last sentence but I know I was able to compile with the lcc libs, the problem being that the program was then crashing on the matOpen function call. I do not know if this come from the fact that the lib was not compiled wih mingw32. Anyway I think that you will have a hard time to have a cross-platform BCI2000, good luck !

I am not sure I understand what you meant by your last sentence but I know I was able to compile with the lcc libs, the problem being that the program was then crashing on the matOpen function call. I do not know if this come from the fact that the lib was not compiled wih mingw32. Anyway I think that you will have a hard time to have a cross-platform BCI2000, good luck !

### Who is online

Users browsing this forum: No registered users and 0 guests