Invalid MEX-FILE in MATLAB 2017 prerelease version

Hi Everyone,

I have a problem running my code which is written in Dynare and runs in MATLAB. It is a log-linearized model with Bayesian estimation of parameters. The code runs perfectly in earlier versions of MATLAB on both PC and Mac but cannot run after computing steady state in my current version of MATLAB: 2017 prerelease (updated in December 2016).
The error reports:
Invalid MEX-file ‘/Applications/Dynare/4.4.3/matlab/…/mex/matlab/osx64/mjdgges.mexmaci64’:
dlopen(/Applications/Dynare/4.4.3/matlab/…/mex/matlab/osx64/mjdgges.mexmaci64, 6): Library not loaded:
Referenced from: /Applications/Dynare/4.4.3/mex/matlab/osx64/mjdgges.mexmaci64
Reason: image not found.

Does anyone encounter the same problem and does anyone know how to solve this?

I tried copying the ‘mex’ file under Dynare/4.4.3/matlab but it didn’t work, still reporting the same error. I also tried changing the path in the ‘Dynare_config.m’ to make MATLAB follow the path of ‘Dynare/4.4.3/mex’ but still reporting the same error.

Thanks in advance


My first guess is that, with this version, Matlab renamed or removed a shared library that they used to distribute. In any case, I’d recommend you stick with an earlier version of Matlab as Dynare 4.4.3 was released a few years ago it’s not guaranteed to be compatible with versions of Matlab or Octave that have been released since then.

If this problem persists in the official Matlab release, I’ll consider making new mex files and distributing them. I’ll make a post here if I do.

Thank you Houtan. The code does run in earlier versions of MATLAB. I’ll let you know when I get the 2017 official version if the problem still exists.


Hi Houtan,

I’m posting this follow-up replay to let you know that, regarding the problem with invalid MEX-File in MATLAB with Dynare 4.4.3, I updated my MATLAB to the official release R2017a, but the problem remains. It happens after the computation of initial values (steady states). Error reports as below:

Invalid MEX-file
dlopen(/Applications/Dynare/4.4.3/matlab/…/mex/matlab/osx64/mjdgges.mexmaci64, 6):
Library not loaded: @loader_path/libmex.dylib
Referenced from: /Applications/Dynare/4.4.3/mex/matlab/osx64/mjdgges.mexmaci64
Reason: image not found.

Do you have any suggestions for this problem, besides turning the clock back to pre-2017 matlab time?

Many thanks.


Dear Kate,
is the problem also present when you use the unstable version of Dynare?

Hi Kate,

I’m unable to produce the same problem as you’re experiencing, but I am encountering other problems and am working to fix them.

My question for you is, does your code run with Dynare 4.4.3 or the unstable version on a previous version of Matlab?

I am experiencing the same problem, which cropped up when I updated to Matlab 2017a. I am using the stable 4.4.3 release.

I confirm the problem crops up on MacOS Sierra but not on Windows 10. On windows the new Matlab release runs dynare just fine.


Hi Will,

Do you get the same error as Kate? Does R2016b work for you with Dynare on OS X?

Yes I was getting the same error message, right after the steady state values are displayed. The problem occurs when dynare calls ‘dyn_first_order_solver’

Error in dyn_first_order_solver (line 216)
[err, ss, tt, w, sdim, dr.eigval, info1] =
mjdgges(E, D, DynareOptions.qz_criterium,

Downgraded to Matlab 2016b and dynare runs my mod files fine.


Hi everyone,

I encounter the same problem running Dynare 4.4.3 on Matlab R2017a (official release), running on macOS Sierra. The problem remains when using the unstable Dynare release. I would greatly appreciate a solution (other than downgrading Matlab).


The other solution is to build dynare via homebrew. See this page Follow the directions for Dynare Unstable (which will be the next version of Dynare), replacing R2014b with R2017a and 8.4 with 9.2. If you want to build Dynare 4.4 (current stable), remove --HEAD from the command.

I am not sure I will have the time to make a new dynare release for 4.4. FYI, we hope to have Dynare 4.5 out in the next month or so.

Hi everyone
I encounter the same problem running Dynare 4.4.3 on Matlab R2017a (official), running on macOS Sierra. I try as you said to build dynare via homebrew but got an message error in the final step
==> Installing dynare from homebrew/science
Error: You must brew link ghostscript before homebrew/science/dynare can be installed
I’ve tried all the recommended solution but it still don’t work
Have any other solution

just got the error message after all this step

brew info dynare
homebrew/science/dynare: stable 4.4.3 (bottled), HEAD
Platform for economic models, particularly DSGE and OLG models
Not installed
From: … /dynare.rb
==> Dependencies
Build: boost :heavy_check_mark:, cweb :heavy_check_mark:, xz :heavy_check_mark:
Required: matlab2tikz :heavy_check_mark:, fftw :heavy_check_mark:, gsl :heavy_check_mark:, hdf5 :heavy_check_mark:, libmatio :heavy_check_mark:, metis :heavy_check_mark:, readline :heavy_check_mark:, veclibfort :heavy_check_mark:, suite-sparse ✘
Recommended: octave ✘
==> Requirements
Build: tex :heavy_check_mark:
Required: fortran :heavy_check_mark:
Optional: tex :heavy_check_mark:
==> Options
Matlab version, e.g., 8.2 (to build mex files)
Path to Matlab root directory (to build mex files)
Build documentation
Build without octave support
Install HEAD version
==> Caveats
To get started with dynare, open Matlab or Octave and type:

    addpath /usr/local/opt/dynare/lib/dynare/matlab

10-232-80-132:~ fabriceanicetparfaitdabire$ brew install dynare --with-matlab=/Applications/ --with-matlab-version=9.2 --without-check
Updating Homebrew…
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core, homebrew/science).
==> New Formulae
heimdal lapack make openldap openssh tcl-tk
==> Updated Formulae
afl-fuzz homebrew/science/lumpy-sv
app-engine-java homebrew/science/mir-prefer
arangodb homebrew/science/orocos-kdl
aws-sdk-cpp homebrew/science/picard-tools
awscli jboss-forge
bit jetty
cake kubernetes-cli
chromedriver mercurial
fabio node-build
fio node@4
flow node@6
gollum npth
gotags paket
gpa prettyping
homebrew/science/adam pypy
homebrew/science/afra solr
homebrew/science/circlator stern
homebrew/science/dlib syncthing
homebrew/science/genometools tgui
==> Deleted Formulae

==> Installing dynare from homebrew/science
Error: You must brew link ghostscript before homebrew/science/dynare can be installed
10-232-80-132:~ fabriceanicetparfaitdabire$

Right, so follow the instruction in the error message. It says:

So, at the terminal prompt, type

Also, if you’re not going to use Octave, you can execute the following installation command:

dynare running now after your brew install suggestion
but need to set the path as precise in terminal before running your code
"addpath /usr/local/opt/dynare/lib/dynare/matlab"

I used to set the path like this before
"addpath /Applications/Dynare/4.4.3/matlab"

Maybe you can just try set it like : addpath /usr/local/opt/dynare/lib/dynare/matlab to see if it work without no need to brew install first
I hope this will fix by an update
thank you

Dear Houtan,

Thanks a lot!! The Homebrew installation works fine.

The only minor issue I have right now is that the documentation is not built (even though I used the --with-tex option). Of course, I can easily copy the pdfs from a different computer.


Hi Joris,
did you install the required packages for building the pdf documentation? What is the error message?

Dear Johannes,

I didn’t get any error message, it just didn’t create the PDFs with documentation…

First, I have MacTex installed (without Homebrew).

Second, the following packages seem to be required to build the documentation:

  • GNU Texinfo
  • Texi2HTML and Latex2HTML, if you want nice mathematical formulas in HTML output
  • Doxygen (if you want to build Dynare preprocessor source documentation)
    These are installed via Homebrew and are, as a matter of fact, in the /usr/local/Cellar folder of my computer.

Attached I include one of the log files of the Homebrew Dynare installation (found via the Mac OS Console). It seems to indicate some problems although I am not sure what precisely happens (and how to solve it). Maybe it has something to do with the hyperref package but I am not sure.

Any help would be appreciated! Of course, it’s not really important since it’s easy to find the documentation on the webpage, but other users might face the same issue.

Best, Joris
log_file_homebrew_dynare.txt (406 KB)

That is strange, because in the log-file it clearly says

Output written on dynare.pdf (159 pages, 1147231 bytes).
That means the manual should have been correctly built. Is it maybe in a different folder?