Getting began with C++ MathGL on Home windows and Linux
Posted on June 25, 2020 by Paul
On this article, I’ll present you the best way to set up and get began with the C++ interface of MathGL on Linux and Home windows. MathGL is a top quality scientific graphics library.
Within the first two elements of the article I’ll describe the best way to set up the library and the best way to construct a C++ MathGL instance. Within the third a part of the article we’ll use MathGL to create a 2D operate graphic and reserve it as a picture file. As a second instance, we’ll use the FLTK GUI library to point out the identical 2D operate:
This text is cut up in three elements:
I like to recommend that you just learn the set up half to your OS and the half that exhibits the best way to use MathGL to create some graphics.
Set up MathGL on Home windows:
On Home windows, the advisable method to put in MathGL is to make use of the official MathGL binaries. From the above web page, obtain the GPL or LGPL binaries for MinGW 64 bits. After you’ve completed downloading the archive, you possibly can extract it with 7zip.
Subsequent, we’re going to set up the MinGW 64 GCC toolchain that was used to construct the library. On the present time, best method is to obtain Code::Blocks model 20.03. Be certain to obtain the file named codeblocks-20.03mingw-setup.exe.
Begin the Code::Blocks installer and settle for the defaults. As soon as the set up is completed, Code::Blocks will detect the included GCC toolchain.
Subsequent, you have to to manually copy the content material of the MathGL archive to the situation the place Code::Blocks has put in GCC, that is normally C:Program FilesCodeBlocksMinGW.
Copy the content material of the bin folder of MathGL to the the bin folder of MinGW. When requested if you wish to overwrite some recordsdata with the identical names, skip these recordsdata.
Copy the content material of the lib folder of MathGL to the the lib folder of MinGW.
Open the embody folder of MathGL and replica the embody folder mgl2. Contained in the MinGW folder, go to x86_64-w64-mingw32, open the embody folder and paste the mgl2 folder in right here.
Open Code::Blocks and create a brand new challenge, selected Console Software and C++. Selected a reputation for the challenge and a location.
As soon as the C++ console challenge is open, proper click on on the challenge identify (within the left panel) and choose Construct choices. Choose Linker Settings and within the Different linker choices panel add the specified libraries: -lmgl on this case. If you need to have the ability to use the FLTK GUI library, like you will note in our second instance, you have to so as to add -lmgl -lmgl-fltk. Press OK.
In Code::Blocks, you need to use the Construct and Run button (the small wheel with a inexperienced triangle icon) to compile and execute a program.
Subsequent, take away the default C++ generated code from predominant.cpp and go to MathGL usage a part of this text for an instance.
For Linux, I’ll exemplify the set up half on a Debian primarily based system.
Let’s begin by putting in a C++ toolchain. Open a Terminal and write:
Subsequent, set up MathGL with:
Assuming that you just’ve saved your MathGL program in a file named mgl_ex1.cpp, that is how one can construct it:
or, in case you are utilizing the FLTK GUI library:
As soon as this system is compiled, you possibly can run it as regular on Linux with:
Subsequent, go to the MathGL usage a part of this text for an instance program.
C++ MathGL utilization instance:
Here’s a small C++ MathGL program that may draw a wave curve and save the graphic in a picture file named mgl_example.png:
The picture will probably be saved the place your program executable is positioned.
Subsequent, we’ll draw the identical curve, however this time utilizing a FLTK window that may allow you to play with the graph: zoom, pan, rotate and different operations:
If you wish to be taught extra concerning the capabilities of MathGL I like to recommend that you just test their examples and the user manual.