Categories
Linear Maths in C++

Building for Linux from Windows

I have been a fan of Linux for a very long time. Windows was always been dated, so that you knew when you had to upgrade. That certainty breaks down with Windows 10 continual updates. There’s a Microsoft Reactor session later called “Commercial Marketplace Roadmap”. The latest upgrade gave us WSL2, that supports graphics in Linux. As a commercial programmer I was struggling with modern Windows GUIs. MFC is really old, WPF only runs in .NET, and Qt can only build UWP apps. I’m looking for something else.

I’m getting ahead of myself. Visual Studio 2017 (still dated!) added cross-platform development. The outline is to connect to a remote system using the secure shell (ssh). That remote system provides build and debug facilities. Rather than repeating it, the Microsoft blog describes Linux development.

Having installed as per instructions and restarted, under the menu “File->New->Project, there are Linux options. The most basic is “Console Application (Linux)”. This generates a “main” that looks like this

int main()
{
    printf("hello from ConsoleAppLinux!\n");
    return 0;
}

It might not look like much but it’s quite powerful. Building sends the code to the remote machine and compiles natively. I’m using WSL so I had to install g++ and gdb. Secure shell connection is managed in Visual Studio from Tools->Options and then “Cross Platform”->”Connection Manager.

Vanilla-flavoured Unix, as my professor called it, is not very interesting. WSL2 needs a major Windows update but will allow graphics. Another option under new project is for Raspberry Pi. The generated project “main” is

int main(void)
{
	wiringPiSetupSys();
	pinMode(LED, OUTPUT);

	while (true)
	{
		digitalWrite(LED, HIGH);  // On
		delay(500); // ms
		digitalWrite(LED, LOW);	  // Off
		delay(500);
	}
	return 0;
}

As you can it’s just normal code. The function calls are to a library that mimics Arduino GPIO.

Another development option to investigate is Native Android development. Google have an NDK and Android Studio has a C++ new project template.

Leave a Reply

Your email address will not be published. Required fields are marked *