0

I'm trying to run the matlabdemo.c provided with most copies of matlab (mine being Matlab R2007b) and despite my best efforts I keep getting "unresolved externals" errors when I try to compile the program via the Visual Studio Command Prompt.

I compiled with: "cl -I"C:\Program Files\MATLAB\R2007b\extern\include" matlabdemo.c -link -dll -LIBPATH:"../lib/win64/microsoft/"labeng.lib"

Thanks in advance!

Amro
  • 123,847
  • 25
  • 243
  • 454
DaBird
  • 3
  • 4

2 Answers2

0

You need to link in the MATLAB Engine libraries. On Windows, they're called libeng.dll and libmx.dll, and they're located somewhere in the MATLAB path. Or, use the mex compiler script to build your Engine programs. Here are the two documentation links that describe those two options:

Compiling Engine Applications in an IDE: http://www.mathworks.com/help/techdoc/matlab_external/bsru965.html

Compiling Engine Applications with the MEX command: http://www.mathworks.com/help/techdoc/matlab_external/bsq776w-1.html

Peter
  • 14,559
  • 35
  • 55
0

Here's a sample batch script to compile the engdemo.c program.

Obviously you have to adjust the paths to point to your MATLAB installation (also choose 32/64 bit versions correctly)

compile.bat

call vcvarsall.bat
set MATLABROOT=C:\Program Files\MATLAB\R2012a
cl.exe engdemo.c libeng.lib libmx.lib /Fe"engdemo" /I"%MATLABROOT%\extern\include" /link /libpath:"%MATLABROOT%\extern\lib\win32\microsoft"

You might need to put the MATLAB bin directory on the path when you run it:

set PATH=%MATLABROOT%\bin\win32;%PATH%
Amro
  • 123,847
  • 25
  • 243
  • 454