How to link the MathGL library

Asked By 10 points N/A Posted on -

I am using Visual Studio C Builder and other compilers except mingW/gcc. I need to know how the Math GL library is linked. Also I need to know about building Math GL in Windows. It is to be created GLUT/FLTK/QT windows with calculation in parallel.

Answered By 0 points N/A #100811

How to link the MathGL library


To link mathGl libraries you can include the header file #include <mgl/mgl_w.h> which contain c++ wrapper classes and recognized by any compiler.

You can use the CMake which is utility to compile C code. This is required because all the mathgl are build in pure C and required a CMake + MinGW utilities to build all the libraries under windows. Along with the package you may also need few more graphic related packages such as GSL , PNG , JPEG etc to build. All these packages can be found and downloaded in the website

You can create parallel calculation by creating separate thread for processing window messages. You can you the GNU libraries Pthread library to create thread in generic way. Data can be updated using the function mg1graphFLTK::update().

Please find a sample code for your reference:


#include <mgl/mgl_fltk.h>
#include <pthread.h>
#include <unistd.h>
mglPoint pnt; 
int sample(mglGraph *gr, void *)
  gr->Box();  gr->Line(mglPoint(),pnt,"Ar2");
  return 0;
void *mgl_fltk_tmp(void *)      {       mglFlRun();     return 0;       }
int main (int argc, char ** argv)
  mglGraphFLTK gr;
  gr.Window(argc,argv,sample,"test");  // create window
  static pthread_t tmp;
  pthread_create(&tmp, 0, mgl_fltk_tmp, 0);
  pthread_detach(tmp);    // run window handling in the separate thread
  for(int i=0;i<10;i++)   // do calculation
    sleep(1);             // which can be very long
    pnt = mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1);
    gr.Update();          // update window
  return 0;   // finish calculations and close the window

Login/Register to Answer

Related Questions