How to fix Matlab mex error: You can't use 'macro parameter character #' in vertical mode.
Problem
While trying to compile your Matlab or Simulink S-Function using a command such as
mex_error_example.sh
mex mysfunction.cppyou get the following error:
example.txt
This is pdfTeX, Version 3.141592653-2.6-1.40.26 (TeX Live 2024) (preloaded format=mex)
restricted \write18 enabled.
entering extended mode
(./sine_wave_generator.cpp
This is MeX Version 1.05 18 XII 1993 (B. Jackowski & M. Ry\'cko)
! You can't use `macro parameter character #' in vertical mode.
l.1 #
define S_FUNCTION_NAME sine_wave_generator
?Solution
The issue here is that you are not using mex from Matlab, but a different TeX-based program called mex. This is likely due to the mex binary being in your PATH environment variable before the Matlab binary directory.
To fix this, you can either:
- Use the full path to the
mexbinary in your Matlab installation, e.g./usr/local/MATLAB/R2021b/bin/mex, or - Change the order of directories in your
PATHenvironment variable so that the Matlab binary directory comes before the othermexbinary directory. - Use the
mexcommand from the Matlab command line, which should automatically use the correct binary.
Check out similar posts by category:
Matlab/Simulink, C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow