Solarian Programmer

My programming ramblings

Install Python with NumPy SciPy Matplotlib on macOS Big Sur (Apple Silicon arm64 version)

Posted on June 15, 2021 by Paul

In this article, I will show you how to install Python with NumPy, SciPy and Matplotlib on macOS Big Sur. I will show you how to install natively the above three libraries using arm64 Apple Silicon versions. I assume that you have one of the M1 or newer arm64 processors. If you have an Intel based Mac, please check my other article.

MacOS Big Sur comes by default with Python 2.7 which, at this point, receives only bug fixes and is EOL since 2020. Python 3 is the future and it is supported by all major Python libraries. In this tutorial, we’ll use Python 3.9 which is the latest stable release of Python at the time of this writing.

Start by installing the Command Line Tools for macOS. Please note, that you will need the Command Line Tools even if you’ve already installed Xcode. Open a Terminal and write:

1 xcode-select --install

►  Continue reading


Getting Started with Clang and Visual Studio Code on Windows with MSYS2 and MinGW-w64

Posted on June 11, 2021 by Paul

This is a short introduction in getting started with Clang on Windows 10 under MSYS2 and MinGW-w64. The Clang and LLVM binaries from https://llvm.org/ require that you to have Visual Studio 2019 installed on your machine, MSYS2 is a lighter alternative. In the last part of this article, I will show you how to use VS Code to build and debug a simple C++ program.

This article is split into three parts:

►  Continue reading


Enable OpenSSH server on Windows 10

Posted on October 27, 2020 by Paul

In this article, I will show you how to enable the OpenSSH server on Windows 10 and how to connect through ssh to a Windows 10 machine.

By default, recent versions of Windows 10 have an OpenSSH client already installed, this means that you can use a Windows 10 machine to connect through ssh to other machines, typically Linux servers, that have an ssh server enabled. How about when you want to be able to connect through ssh to another Windows computer ?

►  Continue reading


Using the Visual Studio Developer Command Prompt from the Windows Terminal

Posted on October 25, 2020 by Paul

In this article, I will show you how to use the Visual Studio command line compiler from the Windows Terminal. I will assume that you’ve already installed Visual Studio 2019 on your machine. In my case, I have installed the Community edition with the Desktop development with C++ workload. By default, the installer will create a few links for using the development tools from the classical Windows Command Prompt and we are going to copy some settings from this to the Windows Terminal. My second assumption is that you’ve also installed the Windows Terminal, if this is not the case just open Microsoft Store, search for Windows Terminal and install it.

If you’ve ever played with Windows Terminal you already know why it is nicer to use than the classical Command Prompt, a few examples: tabs, vertical and horizontal splits, a resizable window, zoom in and out, proper copy paste to and from the Terminal, background colors and a lot of other possible customizations.

►  Continue reading


Getting started with C++ MathGL on Windows and Linux

Posted on June 25, 2020 by Paul

In this article, I will show you how to install and get started with the C++ interface of MathGL on Linux and Windows. MathGL is a high quality scientific graphics library.

In the first two parts of the article I will describe how to install the library and how to build a C++ MathGL example. In the third part of the article we’ll use MathGL to create a 2D function graphic and save it as an image file. As a second example, we’ll use the FLTK GUI library to show the same 2D function:

MathGL Demo two dimensional wave curve function

This article is split in three parts:

I recommend that you read the install part for your OS and the part that shows how to use MathGL to create some graphics.

►  Continue reading


Getting started with GSL - GNU Scientific Library on Windows, macOS and Linux

Posted on January 26, 2020 by Paul

In this article, I will show you how to install GSL - the GNU Scientific Library on Windows, macOS and Linux, and how to compile and run a simple GSL program. GSL is a C library for numerical computations. You can use GSL for example to solve a linear system of equations, to fit a curve to a set of points, for numerical integration, statistical calculations and so on. You can find a detailed description of GSL capabilities in the GSL reference manual.

This article is split in a few parts:

I recommend that you read the install part for your OS and the part that shows how to use GSL to solve a linear system of equations.

►  Continue reading


Install Code::Blocks and GCC 9 on Windows - Build C, C++ and Fortran programs

Posted on November 16, 2019 by Paul

In this article I will show you how to install the Code::Blocks IDE on Windows and how to configure it to use GCC 9 for building C, C++ and Fortran programs. The advantage of this setup is that you will be able to compile any standard C99, C11, C++11, C++14, C++17 and Fortran program on your Windows machine. Please note, that Code::Blocks is available in two versions: as a standalone IDE, as an IDE and an outdated version of GCC (5.1.0). I will show you how to use the latest version of GCC, which is 9.2 at the time of this writing, with the Code::Blocks IDE.

I recommend that you start by installing the latest version of GCC, by following my previous article, in which I’ve shown how to install GCC 9.2 with the MSYS2 software distribution. Once you have GCC installed, you can proceed with installing Code::Blocks.

There is also a video version of this tutorial:

The article consists of five parts:

►  Continue reading


C++ Implementing a Chaos Game simulator

Posted on November 13, 2019 by Paul

In this article, I will show how to implement in C++ the classical Chaos Game. We start with a regular polygon and a random initial point inside the polygon. Next, we randomly select one of the polygon vertices and add a new point at a fraction of the distance between the initial point and the polygon vertex. We take as initial point the newly generated point and iterate for a large number of steps. Following the above process can, in some cases, produce a fractal shape.

In the next image you can see various fractal shapes generated with the program we are going to write in this post:

Various images generated with the simulator

►  Continue reading


Install GCC 9 on Windows - Build C, C++ and Fortran programs

Posted on November 5, 2019 by Paul

In this article, I will show you how the install the GCC compilers on your Windows system using the MSYS2 software distribution.

The advantage of this setup is that you will be able to build C, C++ and Fortran programs on your Windows machine and generate native Windows executables. Also, MSYS2 tends to offer the latest stable versions of GCC, which at the time of this writing is 9.2.

There is also a video version of this tutorial:

Another advantage of using the MSYS2 software distribution is that you will be able to install, if necessary, other C and C++ libraries like SDL2 or OpenCV using the pacman package manager which is included with MSYS2.

Please note that all graphical libraries provided by MSYS2 use the native Win32 API. This means that when you build for example an OpenGL application it will use a native Windows Win32 window.

►  Continue reading


C++20 span tutorial

Posted on November 3, 2019 by Paul

According to the latest C++20 draft, a span is a non-owning view over a contiguous sequence of objects. In other words, a std::span is, in essence, a pointer, length pair that gives the user a view into a contiguous sequence of elements. The elements of a span can be, for example, stored in one of the standard library sequential containers (like std::array, std::vector), in a built-in C-style array or in a memory buffer.

Here is a simple example of using std::span as a general interface for a print function that receives as argument a contiguous sequence of integers:

 1 // span_0.cpp
 2 #include <iostream>
 3 #include <vector>
 4 #include <array>
 5 #include <span>
 6 
 7 void print_content(std::span<int> container) {
 8     for(const auto &e : container) {
 9         std::cout << e << ' ';
10     }
11     std::cout << '\n';
12 }
13 
14 int main() {
15     int a[]{23, 45, 67, 89};
16     print_content(a);
17 
18     std::vector v{1, 2, 3, 4, 5};
19     print_content(v);
20 
21     std::array a2{-14, 55, 24, 67};
22     print_content(a2);
23 }

►  Continue reading


A Happy Halloween from C++ and an IIFE lambda

Posted on October 31, 2019 by Paul

Happy Halloween, from C++:

 1 // halloween.cpp
 2 #include <iostream>
 3 
 4 const auto dummy1 = [] {
 5     std::cout << "Hold my beer!\n";
 6     return 1;
 7 }();
 8 
 9 const auto dummy2 = [] {
10     std::cout << "Hold my second beer!\n";
11     return 2;
12 }();
13 
14 
15 int main() {
16     std::cout << "C++: Happy Halloween, your program starts here!\n";
17 }

Using an IIFE, or an “Immediately invoked function expression”, lambda to initialize a global variable can have surprising side effects:

►  Continue reading


C++17 - find the greatest common divisor, gcd, of two or more integers

Posted on October 25, 2019 by Paul

In this article, I will show you how to find the gcd - greatest common divisor of two or more integers with C++, by using two implementations of the classical Euclid algorithm. As a side note, the C++ standard library has a std::gcd function that can calculate the gcd of two numbers and I will also show you how to use the STL version. Implementing an algorithm from scratch is the best way to understand it, even though in practice one should use as much as possible the solution already provided by the language standard library.

There is also a video version of this tutorial:

By definition, the gcd of two or more integers, that are not all zero, is the largest positive integer that divides all these numbers. For example:

gcd(9, 15) = 3
gcd(9, 15, 21) = 3
gcd(0, 10) = 10

It is also useful to define:

gcd(0, 0) = 0.

►  Continue reading


Install OpenCV 4 with Python 3 on macOS Catalina

Posted on October 21, 2019 by Paul

Updated 11 February 2020

In this article, I will show you how to install OpenCV 4 with Python 3 on macOS Catalina.

There is also a video version of this tutorial:

MacOS comes by default with Python 2.7 which, at this point, receives only bug fixes and will be EOL by 2020. Python 3.x is the future and it is supported by all major Python libraries. In this tutorial, we’ll use the Python 3.8.

Start by installing the Command Line Tools for macOS. Please note, that you will need the Command Line Tools even if you’ve already installed Xcode. Open a Terminal and write:

1 xcode-select --install

Once the Command Line Tools are installed, we can install Python.

►  Continue reading


Compiling GCC 10 on macOS Catalina

Posted on October 12, 2019 by Paul

Updated 8 May 2020

In this tutorial, I will show you how to compile from source and install the current stable version of GCC on your macOS computer. The instructions from this tutorial were tested on Catalina (macOS 10.15).

Clang, the default compiler for macOS, supports only C, C++, Objective-C and Objective-C++. If you are interested in a modern Fortran compiler, e.g. you will need gfortran that comes with GCC. Another reason to have the latest stable version of GCC on your macOS is that it provides you with an alternative C and C++ compiler. Testing your code with two different compilers is always a good idea.

Building GCC 10 from sources could take some time, in my case it took about two hours on a MacBook Air with a 16GB of RAM.

►  Continue reading


Install OpenCV 4 on Raspberry Pi for C++ and Python development

Posted on September 17, 2019 by Paul

In this article, I will show you how to install OpenCV 4 with Python and C++ support on Raspberry Pi. I assume that you have the latest Raspbian installed on your Raspberry Pi, which at the time of this writing is based on Debian 10 Buster.

Unfortunately, there is no official binary of OpenCV 4 for Raspberry Pi, so I had to built OpenCV with Python 2 and 3 support for Raspberry Pi Zero and up from sources. If you want to do the build yourself check my previous articles:

In this article I’ll will show you how to install the already built binaries.

There is also a video version of this tutorial:

►  Continue reading