Error using mex compiler on a really simple example (too many sections / Fatal error: can't close / File too big)

Hello everyone,
I am working on a project that rely on exprtk. I need to interpret some functions in a language supported by the library that are stored as strings. The library is written as a single .hpp file and I am using a .cpp mex file as interface (I know it is possible to import an header-only HPP file directly but that is not what I need here).
My issue is that the compilation of my program triggers an error that I cannot find elsewhere online (too many section / can't close / file too big). You can find attached a minimum example that produce the error (ParseFunction.cpp) as well as the library (exprtk.hpp). Here is a the log error that I get (as MATLAB code for readability):
Error using mex
C:/ProgramData/MATLAB/SupportPackages/R2022a/3P.instrset/mingw_w64.instrset/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/../../../../x86_64-w64-mingw32/bin/as.exe:
C:\Users\Theo\AppData\Local\Temp\mex_59947787181745_17940\ParseFunction.obj: too many sections
(59911)
C:\Users\Theo\AppData\Local\Temp\ccV7ty49.s: Assembler messages:
C:\Users\Theo\AppData\Local\Temp\ccV7ty49.s: Fatal error: can't write 23 bytes to section .text of
C:\Users\Theo\AppData\Local\Temp\mex_59947787181745_17940\ParseFunction.obj because: 'File too big'
C:/ProgramData/MATLAB/SupportPackages/R2022a/3P.instrset/mingw_w64.instrset/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/../../../../x86_64-w64-mingw32/bin/as.exe:
C:\Users\Theo\AppData\Local\Temp\mex_59947787181745_17940\ParseFunction.obj: too many sections
(59911)
C:\Users\Theo\AppData\Local\Temp\ccV7ty49.s: Fatal error: can't close
C:\Users\Theo\AppData\Local\Temp\mex_59947787181745_17940\ParseFunction.obj: File too big
I understand what the issue is (the compiler tries to write to a file that is too big) but I don't get why it happens and how to fix it. It may have to do with the size of the library (40735 lines) or the fact that the functions are inline. Still, I don't see how this could lead to the current error message I get.
Any help or insight would be really useful. Thank you so much in advance,
Théo
Edit:
The .cpp code is less than ten lines and is displayed here as MATLAB
// MATLAB Ming64 version
#include "mex.h"
#include "ext/exprtk.hpp"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[])
{
exprtk::expression<double> expression;
exprtk::parser<double> parser;
parser.compile("This will fail", expression);
}
The line that triggers the error is "parser.compile("This will fail", expression);". If I remove it, the code compiles just fine. I was also able to compile quite a few other functions from the library without facing the same issue (but the compilation time is really long) and compiling basically the same code (see below) using cmake:
// CMake version
#include <ext/exprtk.hpp>
int main()
{
exprtk::expression<double> expression;
exprtk::parser<double> parser;
parser.compile("This will fail", expression);
return 0;
}
I hope these precisions may help to pinpoint the issue and possibly lead to a solution !

 Accepted Answer

To fix this, you need to add "-Wa,-mbig-obj" to the list of used flags. This tells Mingw64 that it needs to support bigger files. Thus, the command becomes:
mex CXXFLAGS='$CXXFLAGS -Wa,-mbig-obj' yourfile.cpp
The compilation takes a few minutes but it works. Hope this helps

More Answers (0)

Categories

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!