Search code examples
cmatlabmatlab-deploymentunresolved-externalmatlab-engine

Matlab R2007b unresolved externals with Engine utility


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!


Solution

  • 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%