64bit Linux opening .mat file in C: library not linking

Hello,
I am trying to open a .mat file in C, but I am having lots of trouble. The code I am running is simple for now:
---------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include "mat.h"
int main(int argc, char **argv)
{
MATFile *spikemat;
const char* name = NULL;
mxArray *reader;
spikemat = matOpen("./data/dataset.mat", "r");
if (spikemat == NULL)
{
printf("Error Opening File");
return();
}
matClose(spikemat);
return 0;
}
-------------------------------------------
However I am getting the following error when trying to compile using "gcc ptsp_detect.c -I /usr/local/MATLAB/R2010b/extern/include" (-I argument is where the header files are located):
In function `main': ptsp_detect.c:(.text+0x22): undefined reference to `matOpen' ptsp_detect.c:(.text+0x52): undefined reference to `matClose' collect2: ld returned 1 exit status
EVEN THOUGH when I look at my paths using echo $LD_LIBRARY_PATH, it spits out the "correct" entries according to [http://www.mathworks.se/help/techdoc/matlab_external/f19027.html].
/usr/local/MATLAB/R2010b/bin/glnxa64:/usr/local/MATLAB/R2010b/sys/os/glnxa64:
What else could be the problem here?
Thanks for any input. Phil

1 Kommentar

philip tully
philip tully am 29 Aug. 2011
Verschoben: Stefanie Schwarz am 13 Sep. 2022
Sorry forgot to add, I am using MATLAB R2010b 64bit version.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Kaustubha Govind
Kaustubha Govind am 29 Aug. 2011

0 Stimmen

The shared object files to add to LD_LIBRARY_PATH are only needed at run-time (when the application attempts to load the libraries). Since you are facing an error during linking, the LD_LIBRARY_PATH setting is not relevant as yet.
You are missing some linker flags to link against the right static libraries. Perhaps the best way to compile this application would be to use the MEX command, as described in the documentation. You may use the verbose (-v) flag with the MEX command, so you can find the exact linker command that needs to be used.

2 Kommentare

philip tully
philip tully am 30 Aug. 2011
Verschoben: Stefanie Schwarz am 13 Sep. 2022
Beautiful, thanks Kaustubha!
Your documentation seems do not work!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by