Arritmic
Arritmic

Reputation: 509

Read Mat Files in C++ in a Qt project

I am trying to read a mat-file in an own mat_file_read.cpp in a Qt project, and I am having problems. My error:

error lnk2019: unresolved external symbol matOpen referenced in function "int __cdecl read_mat_file(class QString)" (?read_mat_file@@YAHVQString@@@Z)"

In my project.pro, I am including:

INCLUDEPATH += C:\Program Files\MATLAB\MATLAB Production Server\R2015a\extern\include\
LIBS += -LC:\Program Files\MATLAB\MATLAB Production Server\R2015a\bin\win64
        -llibmx
        -llibmat
        -llibeng

In the header of my cpp file:

#include <stdio.h>
#include <stdlib.h>
#include "mat.h"
#include "matrix.h"
#include <QString>
#include <QFileDialog>

In my mat_file_reader.cpp:

#include "read_mat_file.h"
int read_mat_file(QString file)
{

    // Variable definition
    int result;
    MATFile *pmat;

    if (file.isEmpty()) return 0;
    QByteArray ba = file.toLatin1();
    const char *rootFile = ba.data();
    pmat = matOpen(rootFile,"r");

    result = 0;

  return (result==0)?EXIT_SUCCESS:EXIT_FAILURE;

}

And the curious thing is the Qt editor is recognizing the functions from "mat.h". It is suggesting me the functions....

Thanks so much in advance.

Upvotes: 2

Views: 2046

Answers (2)

lzhbrian
lzhbrian

Reputation: 56

I think maybe it's because you forget your \ in the end of your lines. And also, maybe you need to avoid having spaces in your path, or try putting it in $$quote(), like the following:

INCLUDEPATH += $$quote(C:/Program Files/MATLAB/MATLAB Production Server/R2015a/extern/include)
LIBS += -L$$quote(C:/Program Files/MATLAB/MATLAB Production Server/R2015a/bin/win64) \
        -llibmx \
        -llibmat \
        -llibeng

Upvotes: 1

Arritmic
Arritmic

Reputation: 509

Finally I found a solution, although I don't understand fine why.... I only changed the next lines in my project.pro of Qt:

INCLUDEPATH += C:\Program Files\MATLAB\MATLAB Production Server\R2015a\extern\include\
LIBS += -llibmx -LC:\librerias\matlab\extern\lib\win64\microsoft
LIBS += -llibmat -LC:\librerias\matlab\extern\lib\win64\microsoft
LIBS += -llibeng -LC:\librerias\matlab\extern\lib\win64\microsoft

Now it is working.... It's strange I think, but for me It's ok. :)

Thanks so much @Suever for the support.

Upvotes: 0

Related Questions