0

I'm writing some code that uses a C library provided by MATLAB (to extract data from *.mat files). In my IDE (Code::Blocks), I've included the folder containing the necessary "mat.h", which is on a network drive. My code recognises types defined in mat.h when I do this, but whenever I call functions from the file I get an "undefined reference" error. This is the same case for the example code MathWorks provides. What sort of problem usually causes this?

#include "mat.h"
int main (void) {
   MATFile *pmat; // Compiles only when compiler is told to search in mat.h directory
   pmat = matOpen("example_filename", "r"); // Never compiles
   return 0;
}

Thanks! Cameron

0

2 Answers 2

2

"undefined reference" is normally a linker error. It's not a problem of a header file. You need to tell the linker to link MATLAB's library (or a dedicated object) to your program.

No idea how this is done in Code::Blocks though. In the Code:Blocks documentation it is described here.

1
  • Thanks yes it was a linker issue! Nov 22, 2011 at 22:29
0

Have you checked the contents of mat.h? Does it declare matOpen()? Also, does the error occur when compiling or linking? If it's during the link phase, you probably need to reference the library that contains the implementation of matOpen() (a .lib in Windows, or .a in Unix). The .h file only declares the function.

1
  • Thanks yes it was a linker issue! Nov 22, 2011 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.