Luckyhendrix
Luckyhendrix

Reputation: 1

Trying to use matlab's libmat.dll, but the compiler doesn't recognize the function from the library

I am trying to use matlab libmat.dll in a C application. To compile my C application I use MinGW, for now I use matlab exemple "matcreate.c" and try to compile it, so the projects consist of only one file : main.c .

Here is the makefile I use :

MATINCLUDE  = "C:\Program Files\MATLAB\R2010a\extern\include"
MATLIBRARY  = "C:\Program Files\MATLAB\R2010a\bin\win64"
#
CC       = gcc  
LD       = gcc
CFLAGS   = -O3  -Wall 
LFLAGS   = -Wall -O3 
LIBS     = -I$(MATINCLUDE) -L$(MATLIBRARY)  
#
PROG     = matTest
LISTEOBJ = \
  main.o 

.c.o :
    $(CC) -c  $(CFLAGS) $(LIBS) -o $@ $<
all        : $(PROG)


$(PROG) : $(LISTEOBJ)
    $(LD) -o $(PROG) $(LFLAGS) $(LISTEOBJ) $(LIBS)

clean :
    rm -f *.obj

Here is what I get in the console

E:\Users\Desk\Dropbox\matTest>make

gcc   -c  -O3  -Wall  -I"C:\Program Files\MATLAB\R2010a\extern\include" -L"C:\Pr
ogram Files\MATLAB\R2010a\bin\win64"   -o main.o main.c
gcc -o Hello_world -Wall -O3  main.o  -I"C:\Program Files\MATLAB\R2010a\extern\i
nclude" -L"C:\Program Files\MATLAB\R2010a\bin\win64"
main.o:main.c:(.text.startup+0x48): undefined reference to `matOpen'
main.o:main.c:(.text.startup+0x6e): undefined reference to `mxCreateDoubleMatrix
_730'
e:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: main.o: ba
d reloc address 0x6e in section `.text.startup'
e:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
 failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
make: *** [Hello_world] Error 1

Why do I have "undefined reference to matOpen'" and "undefined reference to mxCreateDoubleMatrix" ?? those function are declared in mat.h. and I added #include "mat.h" to the begining of main.c

thank you

Upvotes: 0

Views: 950

Answers (1)

dohashi
dohashi

Reputation: 1841

Looks like you have included the path to the matlab library, but not the library itself. You need to add a -l<libraryname> to your link line.

Upvotes: 1

Related Questions