File Exchange

image thumbnail


version 1.1.2 (107 MB) by Enrico Bertolazzi
Toolbox for MATLAB interfacing with IPOPT


Updated 20 Nov 2020

From GitHub

View Version History

View license on GitHub

MATLAB interface for IPOPT

This is my rewrite of Peter Carbonetto MATLAB interface for
IPOPT a software package for large-scale ​nonlinear optimization.
Source code and documentation for IPOPT can be downloaded from:
On OSX IPOPT can be installed using Homebrew (

Why do a job already done?

The original MATLAB interface (
seems not maintained for OSX and do not work with recent MATLAB distributions.
I have reorganized and simplified the original interface (only internally) and
eliminated the bug in the interfacing of sparse pattern between MATLAB and IPOPT.
Moreover I tried to improve error catching.

This version contain a toolbox with mex compiled for OSX/LINUX/WINDOWS OS.

Cite As

Enrico Bertolazzi (2021). ebertolazzi/mexIPOPT (, GitHub. Retrieved .

Comments and Ratings (49)

Version 1.1.2 works, thank you!

Enrico Bertolazzi

With the help of Paola Falugi I solved the problem. In practice there where some missing dlls but MATLAB filter the message hiding the reason of the problem. Now in you can find the updated precompiled toolbox that "should" work.

Thank you, I tried an Intel i9 64 bit machine and a Microsoft Surface Pro 3, which is intel i7 64 bit, both on Windows 10. I will try installing a VS2017 redistributable package or the full VS2017 Community Edition and see if that works.

I am beginning to suspect that my issues are due to some external dlls that are there on your computers but not on mine. I will keep digging into it, and if I am able to find out which dll, I will post an update here.

Enrico Bertolazzi

I checked on many computer and its works. So you bust be sure to have the correct hardware software version.
I compiled mex on windows 10, using Visual Studio 2017 on a 64 bit machine (intel i7).
If you have a different architecture e.g. a 32 the precompiled mex cannot work.
To check the architecture run `computer` on a matlab command windows. If the command return PCWIN and not PCWIN64
you are using 32 bit architecture and the precompiled mex is not correct.
If the architecture is correct but you have different OS or compiler I cant say if the mex work or not.

Same on the second computer! On both computers, I did this:
- Downloaded IPOPT-toolbox.mltbx from GitHub
- Installed the toolbox
- Made sure that "C:\Users\username\AppData\Roaming\MathWorks\MATLAB Add-Ons\Toolboxes\IPOPT-toolbox" and its subdirectories were in matlabpath
- Made sure that the 947 KB binary file "C:\Users\username\AppData\Roaming\MathWorks\MATLAB Add-Ons\Toolboxes\IPOPT-toolbox\bin\windows\ipopt_win.mexw64" was present in the correct directory
- Ran test_ipopt.m to get this:
"Invalid MEX-file 'C:\Users\user\AppData\Roaming\MathWorks\MATLAB Add-Ons\Toolboxes\IPOPT-toolbox\bin\windows\ipopt_win.mexw64':"
"The specified module could not be found."
Any ideas?

Weird, no matter what I do, I get an error. Now it says

"Invalid MEX-file 'C:\IPOPT\bin\windows\ipopt_win.mexw64': The specified module could not be found."

The file ipopt_win.mexw64 is definitely there in that location. I also tried to deleting and recompiling that file (using the MinGW64 compiler). The recompile was successful with no errors/warnings, but when I run an example, I get the same error message above. I will try a different PC and let you know if that works.

Enrico Bertolazzi

You must download the precompiled mex from The file IPOPT-toolbox.mltbx contains precompiled mex for WINDOWS10, linux ubuntu 20, osx Catalina. If you want to compile mex for your OS you can try to use CompileIpoptMexLib, but in this case yoi must have IPOPT installed and working on your OS.
I have tried the installed on a clean windows 10 and its works well. Try to uninstall and then install again the version 1.1.1.

Hi Enrico, thank you so much for maintaining the IPOPT MATLAB interface. I am trying to use it, but when I install the toolbox and run ipopt, I get

Invalid MEX-file 'C:\Users\...\Add-Ons\Toolboxes\IPOPT-toolbox\bin\windows\ipopt_win.mexw64': C:\Users\...\Add-Ons\Toolboxes\IPOPT-toolbox\bin\windows\ipopt_win.mexw64 is not a valid Win32 application.
Error in ipopt (line 251)
[x,info] = ipopt_win(varargin{:});

Windows 10 and MATLAB R2020a. Am I missing a step somewhere?

Enrico Bertolazzi

It is a mistake in the creation of the release in github (its my first release attempt).
The source code and the toolbox was not aligned.
Now the alignment is fixed.
However you do not need to compile anything but simply install the toolbox and use it.

Haosen Xing

Hi Enrico, the "Source code" you just uploaded in seems to miss 'ipopt' function. You might forget to copypaste it. It is a pure script.

Enrico Bertolazzi

Due to the difficulty to compile IPOPT and link the MEX I produced in the last version a Toolbox that can be downloaded at The toolbox contains binary for OSX/LINUX/WINDOWS and cannot be uploaded directly in `File Exchange` site due to toolbox size limit.


Thanks to Enrico. I am using MATLAB2019b on a windows computer. Binary and precompiled_mex ipopt.mexw64 cannot be executed. Like Karl, The error I get is: "Invalid MEX-file '... \ipopt.mexw64': The specified procedure could not be found." However, I did use the command precompiled_mex for XOS (ipopt.mexmaci64) to confirm that it works in windows. I would be honored if I could be of any help!

Karl Mårtensson

Hi. I've tried the pre compiled version of "ipopt.mexw64", but can't get it to work. I've tested both mex files (in "precompiled_mex\WindowsMex64" and "binary/dll"). The error I get is: "Invalid MEX-file '...\ipopt.mexw64': The specified procedure could not be found.". I run Matlab version ' (R2020a) Update 4'. Do you know what I should do?

Enrico Bertolazzi

Have you tried the ipopt.mexw64 compiled by me? It is on directory mexIPOPT/binary/dll/ of the github distribution at

Zhibin Deng

Thanks, Enrico. I did use mingw64 to produce the MEX file "ipopt.mexw64" in MATLAB. Still, it does not work.

Enrico Bertolazzi

If you use the precompiled DLL of IPOPT you must use mingw64 to produce the MEX in MATLAB.

Zhibin Deng

Even if I put the "icudt61.dll" into the same directory with ipopt.mexw64, it still doesn't work. I google the problem. It may be due to that "ipopt.mexw64" is compiled by MinGW64, but the shared dependent libraries are not. I'm not sure though.
Anyway, thank you for sharing this interface.

Enrico Bertolazzi

I am not sure that it work for you, but normally all the DLL must be in the same directory where ipopt.mexw64 is located.

Zhibin Deng

Hi. I successfully build the new mex file "ipopt.mexw64". But I encountered an error when running the "test_ipopt.m" in the "example" folder. It says that "some shared library is missing: icudt61.dll .....". But I checked that the file "icudt61.dll" is indeed in the folder. I wonder how to fix this. Thank you.

Enrico Bertolazzi

Ipopt now have changed the way it compile, thus my readme on Ipopt compilation is obsolete, sorry.
You should read the documentation of Ipopt. Xcode_6.1.1 is quite old, Xcode 11 is the actual version, or 10 if you do not have Catalina OS.

Ramsha Khan

Hi, I'm having some trouble understanding the readme file instructions especially the order in which I need to compile/install. I am relatively new to using bash so I'm having trouble understanding what I need to do before I try to run the precompiled mex (at the moment it causes my Matlab to crash). i have OSX 10.14 and Matlab R2015a. I installed ipopt using brew. In the readme you talk about Xcode, but I didn't know whether I need to download it myself or I should already have it. In any case I'm installing Xcode_6.1.1. You give instructions in "README_osx_how_to_compile_ipopt" to get Mumps using "cd ThirdParty/Mumps" but there is no subdirectory Mumps. If you could clarify where I find this/ what I would need to have installed beforehand, that would be really helpful!

Shuai Heng

For windows user, I tried the 'ipopt.mexw64' in the folder 'precompiled_mex', but it didn't work. Then I build new mex file with '../lib/compile_win.m', which need MinGw (can be installed on the add-ones). Now I can use IIPOPT. The new file will be in the '../binary/dll' folder.

Jordan Kio

Hi Sir, I am using OSX 10.13 and R2019a. The pre-compiled mex has an error dialog when opening. "Error using open (line 146)"

Enrico Bertolazzi

[Q: Is it still up to date? Somehow none of this works for me]

I use this mex on OSX 10.15.1 and was compiled with a previous OS.
The precompiled mex should work on OSX 10.13.

Maximilian Schelle

Is it still up to date? Somehow none of this works for me.
I'm using OSX 10.13 and R2018b/R2019a

Enrico Bertolazzi

For windows I was not able to compile IPOPT (using MINGW), thus I used the precompiled DLL from These DLLs do not activate the interface with ma57.

Kenneth Chao

Hi, I am wondering us that possible to use this IPOPT interface with ma57 in windows?
In compile_win.m I saw -lmwma57 is added in the CXXFLAGS, but the mex IPOPT is still runs with mumps.

Marco Frego

Randall Rausch

Used the precompiled mex and that worked, so sorry for the rather lengthy previous question!

Randall Rausch


I've tried to follow the instructions given by Deepak Ingole and I'm getting the following:

>> compile_osx
Verbose mode is on.
... Looking for compiler 'Xcode Clang++' ...
... Looking for environment variable 'DEVELOPER_DIR' ...No.
... Executing command 'xcode-select -print-path' ...Yes ('/Applications/').
... Looking for folder '/Applications/' ...Yes.
... Executing command 'which xcrun' ...Yes ('/usr/bin/xcrun').
... Looking for folder '/usr/bin' ...Yes.
... Executing command 'defaults read IDEXcodeVersionForAgreedToGMLicense' ...Yes ('4.6').
... Executing command '
if echo $agreed | grep -E '[\.\"]' >/dev/null; then
lhs=`expr "$agreed" : '\([0-9]*\)[\.].*'`
rhs=`expr "$agreed" : '[0-9]*[\.]\(.*\)$'`
if echo $rhs | grep -E '[\."]' >/dev/null; then
rhs=`expr "$rhs" : '\([0-9]*\)[\.].*'`
if [ $lhs -gt 4 ] || ( [ $lhs -eq 4 ] && [ $rhs -ge 3 ] ); then
echo $agreed
exit 1
fi' ...Yes ('4.6').
... Executing command 'xcrun -sdk macosx --show-sdk-path' ...Yes ('/Applications/').
... Executing command 'xcrun -sdk macosx --show-sdk-version' ...Yes ('10.13').
... Executing command 'clang --version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]'|head -1' ...Yes ('9.1.0').
Found installed compiler 'Xcode Clang++'.
Set INCLUDE = /Applications/;/Applications/;/Applications/;/Applications/;/Applications/;/Applications/;/Applications/;/Applications/;/Applications/;/Applications/;
Options file details
Compiler location: /Applications/
Options file: /Users/randall/Library/Application Support/MathWorks/MATLAB/R2018a/mex_C++_maci64.xml
CMDLINE200 : /usr/bin/xcrun -sdk macosx10.13 clang++ -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/ -framework Cocoa -bundle -stdlib=libc++ -Xlinker -rpath -Xlinker /opt/intel/mkl/lib -framework Accelerate -O -Wl,-exported_symbols_list,"/Applications/" -Wl,-exported_symbols_list,"/Applications/" -Wl,-U,_mexCreateMexFunction -Wl,-U,_mexDestroyMexFunction -Wl,-U,_mexFunctionAdapter -Wl,-exported_symbols_list,"/Applications/" /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/ipopt.o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/IpoptInterfaceCommon.o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/cpp_mexapi_version.o /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libgfortran.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libquadmath.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/libgcc.a -lipopt -lmumps_common -lsmumps -ldmumps -lcmumps -lzmumps -lpord -lscalapack -lmpiseq -L/usr/local/lib -L"/Applications/" -lmx -lmex -lmat -L"/Applications/" -lMatlabDataArray -lMatlabEngine -o ipopt.mexmaci64
CC : /usr/bin/xcrun -sdk macosx10.13 clang
CXX : /usr/bin/xcrun -sdk macosx10.13 clang++
CFLAGS : -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/
CXXFLAGS : -fPIC -O3 -DMATLAB_MEXFILE -mmacosx-version-min=10.9
INCLUDE : -I"../src" -I"/usr/local/include" -I"/usr/local/include/coin" -I"/Applications/" -I"/Applications/"
LD : /usr/bin/xcrun -sdk macosx10.13 clang
LDXX : /usr/bin/xcrun -sdk macosx10.13 clang++
LDFLAGS : -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/ -framework Cocoa -bundle -stdlib=libc++ -Xlinker -rpath -Xlinker /opt/intel/mkl/lib -framework Accelerate
LDBUNDLE : -bundle
LINKEXPORT : -Wl,-exported_symbols_list,"/Applications/"
LINKEXPORTVER : -Wl,-exported_symbols_list,"/Applications/"
LINKEXPORTCPP : -Wl,-U,_mexCreateMexFunction -Wl,-U,_mexDestroyMexFunction -Wl,-U,_mexFunctionAdapter -Wl,-exported_symbols_list,"/Applications/"
LINKLIBS : /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libgfortran.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libquadmath.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/libgcc.a -lipopt -lmumps_common -lsmumps -ldmumps -lcmumps -lzmumps -lpord -lscalapack -lmpiseq -L/usr/local/lib -L"/Applications/" -lmx -lmex -lmat -L"/Applications/" -lMatlabDataArray -lMatlabEngine
LDEXT : .mexmaci64
SETENV : CC="/usr/bin/xcrun -sdk macosx10.13 clang"
CXX="/usr/bin/xcrun -sdk macosx10.13 clang++"
CFLAGS="-fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/ -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE "
LD="/usr/bin/xcrun -sdk macosx10.13 clang"
LDXX="/usr/bin/xcrun -sdk macosx10.13 clang++"
LDFLAGS="-Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/ -framework Cocoa -bundle -stdlib=libc++ -Xlinker -rpath -Xlinker /opt/intel/mkl/lib -framework Accelerate /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libgfortran.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libquadmath.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/libgcc.a -lipopt -lmumps_common -lsmumps -ldmumps -lcmumps -lzmumps -lpord -lscalapack -lmpiseq -L/usr/local/lib -L"/Applications/" -lmx -lmex -lmat -L"/Applications/" -lMatlabDataArray -lMatlabEngine -Wl,-exported_symbols_list,"/Applications/""
XCODE_DIR : /Applications/
XCRUN_DIR : /usr/bin
ISYSROOT : /Applications/
SDKVER : 10.13
MATLABROOT : /Applications/
ARCH : maci64
SRC : "/Users/randall/ticom-geo/projects/waterMoccasin/ebertolazzi-mexIPOPT-23d8c02/lib/../src/";"/Users/randall/ticom-geo/projects/waterMoccasin/ebertolazzi-mexIPOPT-23d8c02/lib/../src/";"/Applications/"
OBJ : /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/ipopt.o;/var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/IpoptInterfaceCommon.o;/var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/cpp_mexapi_version.o
OBJS : /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/ipopt.o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/IpoptInterfaceCommon.o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/cpp_mexapi_version.o
SRCROOT : /Users/randall/ticom-geo/projects/waterMoccasin/ebertolazzi-mexIPOPT-23d8c02/lib/../src/ipopt
DEF : /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/ipopt.def
EXP : "ipopt.exp"
LIB : "ipopt.lib"
EXE : ipopt.mexmaci64
ILK : "ipopt.ilk"
MANIFEST : "ipopt.mexmaci64.manifest"
TEMPNAME : ipopt
EXENAME : ipopt
CMDLINE100_0 : /usr/bin/xcrun -sdk macosx10.13 clang++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE -I"../src" -I"/usr/local/include" -I"/usr/local/include/coin" -I"/Applications/" -I"/Applications/" -fPIC -O3 -DMATLAB_MEXFILE -mmacosx-version-min=10.9 -fPIC -O3 -DMATLAB_MEXFILE "/Users/randall/ticom-geo/projects/waterMoccasin/ebertolazzi-mexIPOPT-23d8c02/lib/../src/" -o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/ipopt.o
CMDLINE100_1 : /usr/bin/xcrun -sdk macosx10.13 clang++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE -I"../src" -I"/usr/local/include" -I"/usr/local/include/coin" -I"/Applications/" -I"/Applications/" -fPIC -O3 -DMATLAB_MEXFILE -mmacosx-version-min=10.9 -fPIC -O3 -DMATLAB_MEXFILE "/Users/randall/ticom-geo/projects/waterMoccasin/ebertolazzi-mexIPOPT-23d8c02/lib/../src/" -o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/IpoptInterfaceCommon.o
CMDLINE100_2 : /usr/bin/xcrun -sdk macosx10.13 clang++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE -I"../src" -I"/usr/local/include" -I"/usr/local/include/coin" -I"/Applications/" -I"/Applications/" -fPIC -O3 -DMATLAB_MEXFILE -mmacosx-version-min=10.9 -fPIC -O3 -DMATLAB_MEXFILE "/Applications/" -o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/cpp_mexapi_version.o
Building with 'Xcode Clang++'.
/usr/bin/xcrun -sdk macosx10.13 clang++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE -I"../src" -I"/usr/local/include" -I"/usr/local/include/coin" -I"/Applications/" -I"/Applications/" -fPIC -O3 -DMATLAB_MEXFILE -mmacosx-version-min=10.9 -fPIC -O3 -DMATLAB_MEXFILE "/Users/randall/ticom-geo/projects/waterMoccasin/ebertolazzi-mexIPOPT-23d8c02/lib/../src/" -o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/ipopt.o
/usr/bin/xcrun -sdk macosx10.13 clang++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE -I"../src" -I"/usr/local/include" -I"/usr/local/include/coin" -I"/Applications/" -I"/Applications/" -fPIC -O3 -DMATLAB_MEXFILE -mmacosx-version-min=10.9 -fPIC -O3 -DMATLAB_MEXFILE "/Users/randall/ticom-geo/projects/waterMoccasin/ebertolazzi-mexIPOPT-23d8c02/lib/../src/" -o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/IpoptInterfaceCommon.o
/usr/bin/xcrun -sdk macosx10.13 clang++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE -I"../src" -I"/usr/local/include" -I"/usr/local/include/coin" -I"/Applications/" -I"/Applications/" -fPIC -O3 -DMATLAB_MEXFILE -mmacosx-version-min=10.9 -fPIC -O3 -DMATLAB_MEXFILE "/Applications/" -o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/cpp_mexapi_version.o
/usr/bin/xcrun -sdk macosx10.13 clang++ -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/ -framework Cocoa -bundle -stdlib=libc++ -Xlinker -rpath -Xlinker /opt/intel/mkl/lib -framework Accelerate -O -Wl,-exported_symbols_list,"/Applications/" -Wl,-exported_symbols_list,"/Applications/" -Wl,-U,_mexCreateMexFunction -Wl,-U,_mexDestroyMexFunction -Wl,-U,_mexFunctionAdapter -Wl,-exported_symbols_list,"/Applications/" /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/ipopt.o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/IpoptInterfaceCommon.o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/cpp_mexapi_version.o /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libgfortran.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libquadmath.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/libgcc.a -lipopt -lmumps_common -lsmumps -ldmumps -lcmumps -lzmumps -lpord -lscalapack -lmpiseq -L/usr/local/lib -L"/Applications/" -lmx -lmex -lmat -L"/Applications/" -lMatlabDataArray -lMatlabEngine -o ipopt.mexmaci64
Recompile embedded version with '-DMATLAB_MEXCMD_RELEASE=R2017b'
/usr/bin/xcrun -sdk macosx10.13 clang++ -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -DMATLAB_MEX_FILE -I"../src" -I"/usr/local/include" -I"/usr/local/include/coin" -I"/Applications/" -I"/Applications/" -fPIC -O3 -DMATLAB_MEXFILE -mmacosx-version-min=10.9 -fPIC -O3 -DMATLAB_MEXFILE "/Applications/" -o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/cpp_mexapi_version.o -DMATLAB_MEXCMD_RELEASE=R2017b
/usr/bin/xcrun -sdk macosx10.13 clang++ -Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=10.9 -Wl,-syslibroot,/Applications/ -framework Cocoa -bundle -stdlib=libc++ -Xlinker -rpath -Xlinker /opt/intel/mkl/lib -framework Accelerate -O -Wl,-exported_symbols_list,"/Applications/" -Wl,-exported_symbols_list,"/Applications/" -Wl,-U,_mexCreateMexFunction -Wl,-U,_mexDestroyMexFunction -Wl,-U,_mexFunctionAdapter -Wl,-exported_symbols_list,"/Applications/" /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/ipopt.o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/IpoptInterfaceCommon.o /var/folders/_z/mgwz1lpj4dxg8s0db9npd4dr0000gn/T/mex_298090465780578_94882/cpp_mexapi_version.o /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libgfortran.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libquadmath.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/libgcc.a -lipopt -lmumps_common -lsmumps -ldmumps -lcmumps -lzmumps -lpord -lscalapack -lmpiseq -L/usr/local/lib -L"/Applications/" -lmx -lmex -lmat -L"/Applications/" -lMatlabDataArray -lMatlabEngine -o ipopt.mexmaci64
MEX completed successfully.
mex -v -cxx CXXFLAGS="-fPIC -O3 -DMATLAB_MEXFILE -mmacosx-version-min=10.9 " CXXOPTIMFLAGS="-fPIC -O3 -DMATLAB_MEXFILE " LDFLAGS='$LDFLAGS -Xlinker -rpath -Xlinker /opt/intel/mkl/lib -framework Accelerate ' -I../src -I/usr/local/include -I/usr/local/include/coin ../src/ ../src/ /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libgfortran.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/../../../libquadmath.a /usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0/libgcc.a -L/usr/local/lib -lipopt -lmumps_common -lsmumps -ldmumps -lcmumps -lzmumps -lpord -lscalapack -lmpiseq
>> test_ipopt
Invalid MEX-file
6): Symbol not found: ___addtf3
Referenced from: /usr/local/opt/gcc/lib/gcc/8/libquadmath.0.dylib
Expected in: /usr/lib/libSystem.B.dylib
in /usr/local/opt/gcc/lib/gcc/8/libquadmath.0.dylib.

Error in ipopt_auxdata (line 41)
[x, info] = ipopt(x0, funcs_new, options_new);

Error in test_ipopt (line 79)
[x, info] = ipopt_auxdata(x0,funcs,options);


Any thoughts? Some version incompatibility?

Thank you

Randall Rausch

Ernst Schwartz

... sorry, my bad, I found the bug, the hessian/jacobian structure didn't match their actual values. thanks for the awesome toolbox, now I just need to get my horrible problem to converge :/

Enrico Bertolazzi

to Ernst Schwartz, can you send me an example with the error so that I can debug?

Enrico Bertolazzi

to Deepak Ingole, thank a lot for the comment. I choose to compile a static version of Ipopt to avoid dependence with dynamic library coming with homebrew.

Ernst Schwartz


Thank you so much for that interface! Unfortunately, I can only get the examples to work, but am having a lot of trouble on my own data.
Specifically, there are two problems, and it seems they have to do with the sparsity patterns
1) isLowerTri in returns false on a matrix that definitely is lower triangular and sparse (funcs.hessianstructure = @(x)(tril(sparse(ones(7)))); )
2) when I set isLowerTri to always return true, I can optimize my problem and the results look reasonable. however when I want to add constraints and specify the jacobianpattern, there are again errors about wrong sizes (In MATLAB function @(x)funcs.jacobian(x,auxdata)
element (1,2) not found in pattern) - but I only have 1 constraint, and variable 2 is not part of it (its jacobian is 0) ...

I'm using Matlab 2015b on an mac with os x 10.10 ... could it be that the sparsity patterns are different here as well?? like I said, the test_ipopt and test_ipopt2 work fine ....

Deepak Ingole

Dear Enrico, thanks for the interface. It worked for me (with the following workaround) on macOS High Sierra (10.13.5) with MATLAB 2018a and Xcode 9.4.
1. Set compiler in MATLAB, by 'mex -setup c++', 'mex -setup c' commands in MATLAB command window.
2. Install "gfortran 6.3" compiler from
3. Install "IPOPT" through homebrew by "brew install dartsim/dart/ipopt" command on terminal
4. Install "scalapack" library through homebrew by "brew install scalapack" command on terminal
5. Download "ebertolazzi/mexIPOP​T" and add its path to MATLAB set path. (You need to add all folders and files, not only "lib".)
6. Go to "lib" folder in MATLAB and run 'compile_osx.m' file. I hope it will not throw any error.
7. Now, test IPOPT by executing 'test_ipopt.m' from "examples" folder.

Tao Lu

Dear Sir, is there a complied mex file for Windows Matlab? Thank you!

Enrico Bertolazzi

updated interface to 3.12.8 with support for MUMPS and MA57 (of MATLAB). Precompiled mex for OSX and Linux are also available.

Frederic Peugny

Apologies if my question is late vs this thread.
I have seen the Matlab Interface page from P. Carbonetto and his comments about sparse matrix.
Could you provide me a beginning of documentation about the sparse matrices for Ipopt?
More precisely I will have a demonstration of Matlab 2017b under Ubuntu
12.04 and I would like to use Ipopt in Matlab
Regards Frederic


Apologies for this bombardment of questions.

I've fixed the Ipopt install I believe (the cause of the other problems). Now I am getting a new error from the install_osx script:
Undefined symbols for architecture x86_64:
"Ipopt::IpoptApplication::Initialize(bool)", referenced from:
_mexFunction in ipopt.o
"Ipopt::IpoptApplication::Statistics()", referenced from:
_mexFunction in ipopt.o
const&)", referenced from:
_mexFunction in ipopt.o
"Ipopt::IpoptApplication::IpoptApplication(bool, bool)",
referenced from:
_mexFunction in ipopt.o
"Ipopt::IpoptApplication::~IpoptApplication()", referenced
_mexFunction in ipopt.o
Ipopt::EJournalLevel)", referenced from:
vtable for Ipopt::MatlabJournal in IpoptInterfaceCommon.o
referenced from:
vtable for Ipopt::MatlabJournal in IpoptInterfaceCommon.o
"Ipopt::Journal::Name()", referenced from:
vtable for Ipopt::MatlabJournal in IpoptInterfaceCommon.o
std::__1::char_traits<char>, std::__1::allocator<char> >
const&, Ipopt::EJournalLevel)", referenced from:
_mexFunction in ipopt.o
"Ipopt::Journal::~Journal()", referenced from:
Ipopt::MatlabJournal::~MatlabJournal() in
Ipopt::MatlabJournal::~MatlabJournal() in
Ipopt::EJournalLevel) const", referenced from:
vtable for Ipopt::MatlabJournal in IpoptInterfaceCommon.o
"typeinfo for Ipopt::Journal", referenced from:
typeinfo for Ipopt::MatlabJournal in
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to
see invocation)


(my note below is for OSX 10.11)


I am trying to install on 2016b. am getting an error

In file included from
../src/IpoptInterfaceCommon.hh:31:10: fatal error:
'IpUtils.hpp' file not found
#include "IpUtils.hpp"

Any ideas?

Paola Falugi

Thank you for the Interface. It works well and the compilation instructions are detailed.

Hi Chao, you need to install gfortran-4.7 and g++-4.7 on your Ubuntu 16.04 LTS.
Also I suggest to create temporary symbolic links for g++-4.7 to g++ and so on (sudo ln -s /usr/bin/g++-4.7 /usr/bin/g++)
because Matlab does not use any more and the mex
command on Matlab R2016a did not allow to specify a different compiler.

Kenneth Chao

Hello, I am using Ubuntu
16.04 LTS 64-bit but I am still trying to be familiar with it. When I follow the procedure and then run compile_linux it shows the following error:
Error using mex
/usr/bin/ld: cannot find -lgfortran
collect2: error: ld returned 1 exit status

Please let me know if you know any suggestion to fix it. Thank you!

Enrico Bertolazzi

I have not yet solved all the linking problems to produce a working mex with windows.

Jens Bremer

Is there a precompiled windows Version available?

Enrico Bertolazzi

mexIPOPT is a wrapper for the IPOPT interface which uses separate call for gradient Hessian etc. It is not possibile (or extremely inefficient) to fuse the call as in matlab optimization toolbox).

Ernst Schwartz

thanks a lot for this. I have a question though: is it somehow possible (as in the matlab optimization tb) to use a single function to compute the objective, its gradient and hessian (eg. [f,g,H]=functionToOptimize(x); )? That would reduce the number of function calls dramatically ...

Enrico Bertolazzi

To use `copy_n` needs to add
#include <algorithm>
in the header file IpoptInterfaceCommon.hh. The updated version should fix the problem



When I try to run the compile_linux.m, after following the instructions in the I get the following errors:

In file included from ../src/
../src/IpoptInterfaceCommon.hh: In member function ‘void IpoptInterface::<anonymous struct>::setup(mxArray*)’:
../src/IpoptInterfaceCommon.hh:168:47: error: ‘copy_n’ was not declared in this scope
../src/IpoptInterfaceCommon.hh:172:7: error: ‘copy_n’ is not a member of ‘std’

mex: compile of ' "../src/"' failed.

Any insight in this problem?

P.S: I run Linux 14.04 LTS 64-bit

MATLAB Release Compatibility
Created with R2020b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!