Read .mat of matlab in qt
-
I am using Qt Creator 2.4.1(Based on Qt 4.7.4) .. Now I want to open the .mat file which I got from Matlab.
I am using the basic function matOpen Initially, I knew the headers required. They are mat.h, matrix.h and tmw.h. Now, before running the code, I need to link the libraries. The required libraries as far as I know are libmat.dll and libmw.dll . I added them to the .pro file as follows.
@
QT += coreQT -= gui
TARGET = mat_open_test
CONFIG += console
CONFIG -= app_bundleTEMPLATE = app
SOURCES += main.cpp
HEADERS +=
mat.h
matrix.h
tmwtypes.hLIBS += -L"C:\Users\skanduri\Documents\C ++\mat_open_test-build-desktop- Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug\libmat.dll"
LIBS += -L"C:\Users\skanduri\Documents\C ++\mat_open_test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK__Debug\debug\libmx.dll"@
Still I get error as : undefined reference to matOpen.. m sure the problem is with the linking.. But I dunno how to solve it. and the compiler Qt is using is MinGw . -
welcome to devnet
I have no experience in binding MathLab stuff to an application.
However, I would expect a .lib to be used in the linking process. This should ensure that all references to MathLab routines are found.
You are trying to reference the .dll directly during linking, but it would be loaded during run time. -
Dear koahnig..
Thanks for the reply.
I also even have the required libraries. They are libmat.lib and libmx.lib.
If I add them to the project as an external library.. Gave the file.
Now the .pro file looked as :
@QT += coreQT -= gui
TARGET = mat_open_test
CONFIG += console
CONFIG -= app_bundleTEMPLATE = app
SOURCES += main.cpp
HEADERS +=
mat.h
matrix.h
tmwtypes.hwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -llibmat
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -llibmatd
else:symbian: LIBS += -llibmat
else:unix: LIBS += -L$$PWD/ -llibmatINCLUDEPATH += $$PWD/../../../../../Program Files/MATLAB/R2012b/extern/include
DEPENDPATH += $$PWD/../../../../../Program Files/MATLAB/R2012b/extern/include
@and the error is :
@cannot find -libmattd@..
I only added libmat.. how can i get the libmatt.d file from?? -
Two I am noticing when looking at your .pro file and the error message.
.pro references libmat and libmatd
the error message indicates that it is looking for libmattd
This is either typo in your posting or the problem.Where do have placed the libs?
$$PWD is your working folder where the source is located.
The folder used in your original post is more the folder of the shadow build. -
Line 26 of your PRO file says, "if building in debug mode on Windows link with libmatd"
Apart from the unnecessary "lib" on the front of the library name, if you don't have debug versions of the Matlib libraries then this will not work.It probably should read (for release):
[code]
win32 {
LIBS += -LC:/path/to/MatLib/bin -lmat
}
[/code] -
@koahnig..
The libmattd is the problem. I have the library libmat.lib .
I copied the library to the folder where main.cpp is. I am adding the library by right clicking on the project->add library->external library->(gave the path of the library). The include path automatically got set.My .pro looks like :
@QT += coreQT -= gui
TARGET = mat_open_test
CONFIG += console
CONFIG -= app_bundleTEMPLATE = app
SOURCES += main.cpp
HEADERS +=
mat.h
matrix.h
tmwtypes.hOTHER_FILES +=
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -llibmat
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -llibmatd
else:symbian: LIBS += -llibmat
else:unix: LIBS += -L$$PWD/ -llibmatINCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
@I get the same error :
cannot find llibmatd..@ChrisW67
What you are saying is correct. I do not have the debug version of the library. But I only have the library. How can I execute it?? Any suggestions -
Since your .pro says explicitly in line 29 that it should use "libmathd" in debug, you cannot compile in debug mode.
For a test try to compile with an additional:
@
CONFIG += release
@than it will use the "libmath".
You may also try to set always:
@
LIBS += -L$$PWD/ -llibmat
@Not sure if you can use release libs for both modes.
-
qkoahnig..
Can you tell me exactly where I should copy the libraries. Should I copy them in the folder containing the main.cpp or in the debug and release subfolders of the main build folder.. and then I can give the subsequent paths while adding.When I added the CONFIG += release..
I get the error ..
Undefined reference to matopen.. The very first problem :( -
[quote author="saratchand" date="1373012556"]qkoahnig..
Can you tell me exactly where I should copy the libraries. Should I copy them in the folder containing the main.cpp or in the debug and release subfolders of the main build folder.. and then I can give the subsequent paths while adding.
[/quote]
That basically depends on your preference. However, it is common practice to keep libs somewhere separate. This has also some practical reasons. You do not want to copy the libs to your source all the time. Furthermore, you do not want mix different 3rd party libs.
As you have figured already, you can supply the path name of the lib's location in the LIBS parameter. I would suggest to leave the libs in their original location (probably in a sub-folder of mathlab). Declare this folder path with with "-L" as you have done already.[quote author="saratchand" date="1373012556"]
When I added the CONFIG += release..I get the error ..
Undefined reference to matopen.. The very first problem :([/quote]
The linker has found the lib now, which is a success.I do not use mathlab, but according to a quick search matopen is a routine of mathlab called in your program.
Possibly there more libs, which you have to declare as well. If there is only one mathlab lib supplied, it looks like it is not compatible with your compiler.
Note, not all libs can be mixed. Typically, they are dependent on the compiler used to build them. That is the reason that you have different download options for Qt libs too. You need to use a build for msvc2010 with msvc2010, msvc2012 with msvc2012, mingw 4.7 with mingw 4.7, mingw 4.4 with mingw 4.4 and so on.
You need to check out the compatibility of your mathlab libs.
-
saratchand , have you solved reading of .mat in qt?
I am having the same problems. I made little more progress than in the last post, but still get "undefined reference to mapOpen".
This is the relevant .pro section I am using
win32: LIBS += -L"C:/Qt/Qt5.1.0/5.1.0/mingw48_32/lib" -llibmat
INCLUDEPATH += $$PWD/matlab
DEPENDPATH += $$PWD/matlabOne hint I have to offer is not to refer to libmatd - that is not necessary and we don't have that anyway. The way I have it above, libmat is used should be used for both the release and debug compilations.
I moved the libmat and include files to the directory showns above to make sure they are found and to prevent some other errors I was getting. Maybe that is not necessary.
However, I am still getting "undefined reference to mapOpen".
Did you maybe find libs and dlls more appropriate for Qt?
-
Hii masheen
Yes I have solved the issue. But i shifted to Visual Studio for the further implementation as I am supposed to here in my institute.Sorry for replying late.
Anyways , This is what my code looks like.@#-------------------------------------------------
Project created by QtCreator 2013-07-03T13:12:22
#-------------------------------------------------
QT += core
QT -= gui
TARGET = mat_open_test
CONFIG += console
CONFIG -= app_bundleTEMPLATE = app
SOURCES += main.cpp
HEADERS +=
mat.h
matrix.h
tmwtypes.hwin32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -llibmat
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -llibmatd
else:symbian: LIBS += -llibmat
else:unix: LIBS += -L$$PWD/ -llibmatINCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/win32:CONFIG(release, debug|release): LIBS += -L$$PWD/ -llibmx
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/ -llibmxd
else:symbian: LIBS += -llibmx
else:unix: LIBS += -L$$PWD/ -llibmxINCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
@One small suggestion, make sure the libraries you are trying to load to your IDE are 32 bit version libraries of Matlab. cos my IDE was 32 bit and I, by mistake tried the 64 bit libraries of Matlab.. Sometimes SHIT!! happens :D ..