1

Please let me know if there is anyway I can get MathGL working on my computer. If there's any mistake in the following tests, pls kindly let me know.
Thank you.
Ok, I've been struggling this issue for quite a long time. Here's what happens when I try to visualize my results from C/Fortran code The basic information is:

OS: Mac OSX 12.3.1
GCC/GFortran version: 11.3.0
clang version: 13.1.6

Case I: Make by default

cmake .
cmake .
make install

This looks like a minimal installation. The header files are installed to /usr/local/include and the libs are installed to /usr/local/lib. The default build is able to compile the following code if I run

**[compile default]**
g++  src/testMathGL.cpp -o testMathGL -lmgl
**[testMathGL.cpp]**
#include "mgl2/mgl.h"
 
 int main() {
    mglGraph gr;
    gr.Title("MathGL Demo");
    gr.SetOrigin(0, 0);
    gr.SetRanges(0, 10, -2.5, 2.5);
    gr.FPlot("sin(1.7*2*pi*x) + sin(1.9*2*pi*x)", "r-2");
    gr.Axis();
    gr.Grid();
    gr.WriteFrame("mgl_example.svg");
}

I believe the default build is good enough to generate plots. However, the plot is generated and automatically saved on disk. it is not convenient if I am debugging my code(may generate lots of plots and I don't need those). Which might be, I need to tune some parameters to obtain a promising and physically realizable setup. So I want the plot generated and open directly after each single run.

Case II:

In that case, I am trying to run the following code

**[testMathGL-fltk]**
#include "mgl2/fltk.h"

int graph(mglGraph *gr) {
    gr->Title("MathGL Demo");
    gr->SetOrigin(0, 0);
    gr->SetRanges(0, 10, -2.5, 2.5);
    gr->FPlot("sin(1.7*2*pi*x) + sin(1.9*2*pi*x)", "r-4");
    gr->Axis();
    gr->Grid();
    return 0;
}

int main() {
    mglFLTK gr(graph, "MathGL demo window title");
    return gr.Run();
}

If I try to compile the code with default command

**[compile default]**
g++  src/testMathGL.cpp -o testMathGL -lmgl (-lmgl-fltk)

The error is straightforward

'mgl2/fltk.h' file not found

Of course, the default build doesn't contain any graphical libraries. To include those libraries, I tried the prebuilt libraries from MathGL. And I compile as

**[compile prebuilt]**
g++  src/testMathGL.cpp -o testMathGL -I/Users/somebody/Downloads/mathgl-8.0-mingw.win64/include/ -L/Users/somebody/Downloads/mathgl-8.0-mingw.win64/lib/-lmgl (-lmgl-fltk)

But g++ keeps giving me the errors like

unknown type name 'dllimport'

As the prebuilt download always has win64 as suffix, I think for Unix-like system, I need to compile it myself. From the installation instructions from MathGL, I am told it is necessary to enable some keys when configuring the make process. see also http://mathgl.sourceforge.net/doc_en/Installation.html

cmake -D enable-all=on -D enable-all-widgets=on -D enable-all-swig=on . 

Then it gives a lot of errors stating missing dependencies. I figured most of them, like Qt5, hdf5, glut, fltk, wxWidgets, swig, octave. Now there are still some missing dependencies I don't know how to resolve. As it shows

CMake Error at CMakeLists.txt:515 (message):
  HDF4_LIB-NOTFOUND


CMake Error at CMakeLists.txt:516 (message):
  HDF4MF_LIB-NOTFOUND


CMake Error at CMakeLists.txt:517 (message):
  HDF4_INCLUDE_DIR-NOTFOUND


CMake Error at CMakeLists.txt:518 (message):
  Couldn't find HDF4 libraries.


CMake Error at CMakeLists.txt:608 (message):
  Couldn't find libHaru or libhpdf.


CMake Error at CMakeLists.txt:612 (message):
  Couldn't find headers of 3d-enabled version of libhpdf.


-- Couldn't find Qt5 WebKitWidgets library. JSON sample disabled.
c-- /usr/local/bin/octave-config x86_64-apple-darwin21.3.0 api-v57
-- Configuring incomplete, errors occurred!
See also "/Users/somebody/Downloads/mathgl-8.0.1/CMakeFiles/CMakeOutput.log".
See also "/Users/somebody/Downloads/mathgl-8.0.1/CMakeFiles/CMakeError.log".

I am wondering how can I install hdf4? or is hdf4 already replaced by hdf5?

francescalus
  • 30,576
  • 16
  • 61
  • 96
Tippsie
  • 39
  • 6
  • Obviously you cannot use windows libs etc. on MacOS, so just delete that completely. But I don't understand why you think you need to build, just to get the header files: didn't you already successfully link? You said you installed the headers into `/usr/local/include` so does that mean you have the file `/usr/local/include/mgl2/mgl.h`, and if so isn't it enough to add `-I/usr/local/include` to your compile line? – MadScientist May 23 '22 at 18:59
  • I do not know or use this package, but there seems to be a port of it... https://ports.macports.org/port/mathgl/ – Mark Setchell May 23 '22 at 20:46
  • Thanks, MadScientist. Yes, I can compile and run my code if I only want to generate a plot figure. But if I need to see the plot immediately on screen, it is necessary to compile with header fltk.h and link to library libmgl-fltk.a (rather than mgl.h and libmgl.a), that's why I am building MatGL with fltk. – Tippsie May 24 '22 at 03:21
  • Yes, ports seems to be a solution. But installation of ports requires Xcode. That's a massive app and I am not willing to use it. Is hdf4 and hdf5 independent? or hdf5 already provide the necessary compatible libraries? – Tippsie May 24 '22 at 03:23

1 Answers1

0

Emmmmm, I have a tricky solution for my requirement above now. Which is call system applications to display the current plots.

#include "mgl2/mgl.h"
#include <iostream>
 
 int main() {
    mglGraph gr;
    gr.Title("MathGL Demo");
    gr.SetOrigin(0, 0);
    gr.SetRanges(0, 10, -2.5, 2.5);
    gr.FPlot("sin(1.7*2*pi*x)", "r-2");
    gr.Axis();
    gr.Grid();
    gr.WriteFrame("mgl_example.svg");
    std::system("open mgl_example.svg -a Gapplin");
}

Still looking for solutions to compile MathGL...

Tippsie
  • 39
  • 6