C library GR¶
Installation¶
You can manually install prebuilt binaries for the GR runtime or install a Linux package.
Operating System |
Architecture |
|
---|---|---|
macOS |
x86_64 |
|
macOS |
aarch64 |
|
macOS |
universal |
|
Debian |
x86_64 |
|
Debian |
aarch64 |
|
Debian |
armhf |
|
Ubuntu |
x86_64 |
|
CentOS 7 |
x86_64 |
|
CentOS 7 |
i386 |
|
Arch Linux |
x86_64 |
|
FreeBSD |
x86_64 |
|
Windows (MinGW) |
x86_64 |
|
Windows (MinGW) |
i686 |
|
Windows (MSVC) |
x86_64 |
You may need to install some additional dependencies on Linux:
- Debian:
apt install libxt6 libxrender1 libxext6 libgl1-mesa-glx libqt6widgets6
- Ubuntu:
apt install libxt6 libxrender1 libxext6 libglx-mesa0 libqt6widgets6
- CentOS / Fedora / Rocky Linux:
yum install libXt libXrender libXext mesa-libGL qt6-qtbase-gui
- openSUSE:
zypper install libXt6 libXrender1 libXext6 Mesa-libGL1 libQt6Widgets6
- Arch Linux:
pacman -S mesa qt6-base
Note: Depending on the Linux flavor you are using, the package names may differ from the ones mentioned here. This particularly applies to the Qt versions used.
- On FreeBSD make sure to install the these packages:
pkg install libXt libXrender libXext mesa-libs qt6
For other versions of GR, see the downloads. For information on building the GR runtime yourself, see Building the GR Runtime.
Docker and other headless Linux systems¶
GR does not rely on X11 for its non-interactive output formats, so you will not need the dependencies listed above on a headless system.
GR3 uses GLX for OpenGL context creation, which requires a connection to an X server. If X, GLX or OpenGL is not available, GR3 will fall back to a built-in software renderer which implements all GR3 functionality except for volume rendering. If you are using a headless sytem, e.g. a Docker container, and want to use
gr_volume()
, you can use Xvfb or similar tools to start an X server that can be used by GR3.
Linux packages¶
Since GR v0.17.2 we provide python-gr .rpm and .deb packages for various Linux distributions using openSUSE Build Service. Your operating systems package manager will cope with package dependencies.
Please follow the installation instructions for your operating system described here.
We also provide Arch packages for C, Python and JavaScript GR on the Arch User Repository:
AUR package name |
Description |
---|---|
Latest stable version of C GR |
|
Latest development version of C GR |
|
Latest stable version of Python GR |
|
Latest development version of Python GR |
|
Latest stable version of gr.js |
|
Latest development version of gr.js |
If you would like to generate video output, make sure the ffmpeg
package is installed before getting any package
from the AUR.
You can either install these AUR packages manually (see the Arch wiki for help) or by using an AUR helper like yay:
yay -S python-gr-framework
In this example, yay
will install C GR (package gr-framework
) as a dependency automatically.
Getting Started¶
After installing GR, you can try it out by creating a simple plot:
#include <stdio.h>
#include <gr.h>
int main(void) {
double x[] = {0, 0.2, 0.4, 0.6, 0.8, 1.0};
double y[] = {0.3, 0.5, 0.4, 0.2, 0.6, 0.7};
gr_polyline(6, x, y);
gr_axes(gr_tick(0, 1), gr_tick(0, 1), 0, 0, 1, 1, -0.01);
// Press any key to exit
getc(stdin);
return 0;
}
To compile and link this example on Linux or macOS, you can run:
cc -I<grdir>/include -L<grdir>/lib -Wl,-rpath,<grdir>/lib -lGR example.c -o example
where you replace <grdir>
with the path to your installation of GR.
Tutorials¶
You can find several tutorials on using GR in the Tutorials section.
API Reference¶
The C API for GR consists of: