0

I want to read some .mat file containing nested structs to use the data for a QT-GUI. So I'm using QT Creator.

My problem right now is, that I don't know what Files I need to call the read functions. Right now I just very simply add all *.h files from matlabroot/extern/include and the file libmat and libmx from matlabroot/bin/win64 to my sourcecode directory.

My code looks like this

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "mat.h"

int main()
{
    MATFile* pmat;

    std::string filename = "x.mat";
    const char* file = filename.c_str();

    printf("Reading file %s...\n\n", file);

    pmat = matOpen(file, "r");
    if (pmat == NULL) {
        printf("Error opening file %s\n", file);
        return (1);
    }

    return 0;
}

I always get the error undefined reference to 'matOpen' but matOpen should be in mat.h.

I just want to run a small minimal example to at least call some of the matlab c++ functions. So I need to know which files are really necessary to put in my working directory.

I'm not really experienced with using someone else's code.

drescherjm
  • 10,365
  • 5
  • 44
  • 64
user7431005
  • 3,899
  • 4
  • 22
  • 49
  • What flags are you using to try to compile this? Did you link the appropriate libraries? – Suever Jan 17 '17 at 14:55
  • 1
    "Undefined reference" errors usually indicate a linker problem - usually omission of requisite libraries; sometimes a library ordering problem. – Toby Speight Jan 17 '17 at 15:17
  • Unless matlab uses a `#pragma comment( lib, "somelibname.lib")` in the headers you added you will need to add the link to the matlab libraries. – drescherjm Jan 17 '17 at 15:23

0 Answers0