troubles with compiling a c++ file including exprTk

1.8k Views Asked by At

I have some troubles compiling a c++ code including exprtk. I want to compile an given example of the package (I called it parser.cpp):

#include <cstdio>
#include <string>
#include "exprtk.hpp"


template <typename T>
void trig_function()
{
   typedef exprtk::symbol_table<T> symbol_table_t;
   typedef exprtk::expression<T>     expression_t;
   typedef exprtk::parser<T>             parser_t;

   std::string expression_string = "clamp(-1.0,sin(2 * pi * x) + cos(x / 2 * pi),+1.0)";

   T x;

   symbol_table_t symbol_table;
   symbol_table.add_variable("x",x);
   symbol_table.add_constants();

   expression_t expression;
   expression.register_symbol_table(symbol_table);

   parser_t parser;
   parser.compile(expression_string,expression);

   for (x = T(-5); x <= T(+5); x += T(0.001))
   {
      T y = expression.value();
      printf("%19.15f\t%19.15f\n",x,y);
   }
}

int main()
{
    trig_function<double>();
    return 0;
}

Therefore I use the following commands in cmd:

g++ -c -o parser.o -Wa,-mbig-obj -I include parser.cpp
g++ -o parser.exe -s parser.o

The exprtk.hpp file is in an include folder in the same directiory as the parser.cpp file.

The first problem is, that the parser.o file is very large (~ 32 Mb) and creating the .exe file take such a long time that I abort the compilation. Furthermore without the -Wa,-mbig-obj flag I get an error. Also I think there is no linking needed because all the code is included in the .hpp file and there are no .dll files or something else. By dropping the flag the error is:

C:/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/as.exe: 
parser.o: too many sections (88691)
C:\..\AppData\Local\Temp\ccE7ythI.s: Assembler messages:
C:\..\AppData\Local\Temp\ccE7ythI.s: Fatal error: can't write parser.o: File too big
C:/Rtools/mingw_64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.3/../../../../x86_64-w64-mingw32/bin/as.exe: parser.o: 
too many sections (88691)
C:\..\AppData\Local\Temp\ccE7ythI.s: Fatal error: 
can't close parser.o: File too big

The source is given via GitHub here. The same error as above occurs if I run make in cmd in the folder where the Makefile is.

Do I miss something or am I too foolish importing the exprtk.hpp file correctly? Any suggestions?

1

There are 1 best solutions below

0
On

You have to have the -mbig-obj flag, which allows for big object files.

As explained here, .obj files have 65536 sections by default.

Exprtk is one big template heavy library (hpp is 1.4M) so it will take a long time to compile and need lots of sections in the object file.