troubles with compiling a c++ file including exprTk
Asked Answered
L

1

11

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?

Libertylibia answered 20/8, 2016 at 15:2 Comment(3)
What's the error in particular? A linker errot?Fulgurate
If I drop the flag it says too many sections and that it can't close the .o file becouse it's too big. With the flag there occurs no error but the compilation from the .o file to the .exe file won't finish. I think there's no linking needed because everything is included in the .hpp file.Libertylibia
Improve your question pleas by adding additional information. Comments aren't realls useful to do so.Fulgurate
C
1

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.

Chapter answered 2/4, 2018 at 14:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.