Category: linux

lldb-mi no longer exists

lldb-mi no longer exists

lldb vs code extensionsThis is debugging vs code with lldb. It seems as of clang-10, it’s no longer supported which is a pita. I’d been working on the Onslaught code and something wasn’t working so I thought I’d try to debug it.  However the debugger wouldn’t start. Investigating a bit further and I found this discussion thread on the GitHub cpp tools.

I have to say this. I find Linux development quite frustrating at times because of things like this. Something that worked in an earlier version of clang has been removed. Why? There’s a similar issue with Ubuntu 18.04 compared to 20.04 running in Hyper-V VM. With 18.04 I can use the clipboard to copy and paste between Windows and Ubuntu, but so far I have been unable to do it in 20.04.

You spend ages wasting time trying to find answers. I find Windows development with C# much less problematic. Open source developers sometimes don’t appear to take the needs of their users as seriously as say commercial developers do.

So now I’m looking a for a better way to debug C/C++ programs from vs code. There is a lldb – vs code adapter as well as native debug and Code LLDB (see screenshots) so I’ll investigate and see if any of these work. Or I can just study my code and work out in my head why it isn’t working!

Interesting article on the state of Linux gaming

Interesting article on the state of Linux gaming

Linux playYes it’s on Medium, but its worth a read. The gist of the article and this one is saying that there’s a problem with Linux for gaming. Also that anyone new to Linux gaming is looking online and finding old articles that suggests that SteamOS is a good distro to use while in reality it hasn’t been updated in a while.  The problem is that Valve (creators of Steam) have let SteamOS languish.

Though its not as if Valve have ignored Linux gaming. They released an open source tool Steam Proton (Link goes to it on GitHub) that lets you run many Windows games (6000 or so)  on Linux. The Linux Steam client includes a copy of Proton.

The problem though is that this hasn’t really helped attract more people to Linux gaming. People I know either play games on Windows or on consoles like PlayStations.  Linux is perceived, wrongly I’m sure as being an inferior game platform.

How to move a SDL project from Windows to Linux

How to move a SDL project from Windows to Linux

SDL Logo
The SDL Logo is from libsdl.org

It’s not actually that hard to do, there’s just a few things that are different between C and Linux, specifically between MSVC and GCC /Clang.. I did this when I wrote the Asteroids game in the book.

Originally I developed it on Windows then moved it to Linux (Ubuntu) and then I added the bits to have it work on a Raspberry Pi. It worked on the Pi more or less as is on Ubuntu but I added support for game pad, detecting that it was on a Pi and displaying the temperature.

Here’s what I’ve found is different between MSVC and GCC/Clang.

  1. The safe string functions. MSVC has the _s functions so instead of strcpy, there’s strcpy_s on MSVC. This doesn’t exists in GCC/Clang but there are similar functions with an n in the middle e.g. strncpy. In future I’ll create a macro for each function that uses the appropriate type so the compiler will pick the correct type.   However it seems even strncpy may not be all that safe. If there is no \0 in the n characters then the copied string won’t have a terminating \0 and thus could still blow up.  This article says that in order of safety it goes like this with strcpy least safe and strlcpy the most.
    strcpy < strncpy < snprintf < strlcpy

    so maybe I should be using strlcpy instead.

  2. The include path for SDL in GCC/Clang is “SDL\SDL.h” not “SDL.h” as it is in MSVC. Again this could be fixed with a macro prefix for the SDL path so all #include works correctly on either system.

3.  I found that the file type was wrong. This wasn’t just a matter of CR/LF versus LF which you get between Windows and Linux (CR = Carriage return, LF = Line feed). Somehow the Windows file had a different UTF encoding type to what GCC/Clang expected and the compiler did not like it. However Visual Studio Code shows you what encoding it is (on the bottom of the edit window) and lets you change it, so no harm done. You may need to do this once on each file you’ve moved from Windows to Linux.

4. I found that the time header file in Linux needed a bit of work to make it compile. The standard for this dictates that differences aren’t done to the header file but by adding in additional headers.

So I’ll look into strlcpy.

 

 

 

Hyper-V VMs are not all the same

Hyper-V VMs are not all the same

Hyper-V Ubuntu installOne of the big problems with Hyper-V and Ubuntu in particular is the clipboard or lack of it. I had 18.04 LTS installed with an X Org RDP login. This worked perfectly and I could have a full screen in my Monitor and could copy/paste.  Don’t underestimate copy/paste.

It’s a real PITA if you have to use say WinSCP to copy files over. I think WinSCP is excellent BTW but the amount of labour saving that copy/paste has done since some genius thought it up is immeasurable. That and allowing the full screen of the monitor are two highly important things.

Sadly the 20.04 LTS didn’t seem to allow it. Copy/paste didn’t work between my Windows PC (host) and Ubuntu (guest). There’s nothing worse than losing a feature you’ve grown fond of.

If you follow these instructions for creating a Hyper-V 18.04, you get the screen size popup but not with 20.04 LTS. For that you have to follow these instructions!

It’s things like this that suggest why Linux Desktop has never been that successful. You can waste many hours getting simple things working and sometimes like Copy/Paste they break between versions. And this is with Ubuntu, probably the biggest and best known and supported Distro.

 

And my Hyper-V Raspi error

And my Hyper-V Raspi error

Scary apt messageSeems to be with Visual Studio Code. I said yesterday that it had got into a funny state. Well I created a new VM and installed the Raspberry Pi OS that runs in a VM and after it updated tried installing VS Code on it.

It would have had the same problem had I let it. The problem is it when you install VS Code, it has some unmet dependencies and in fixing them it wants to remove 8 essential packages and this breaks apt which then gets in a funny state.

No one wants to see this scary message! So I think I may have to use the Code.headmelted.com version on Hyper-V for a while and see if this gets resolved with the next update of VS Code. Ah the jots of software development…

 

An example of what you can do with MonoGame

An example of what you can do with MonoGame

OpenVIII screenshotMonoGame is not just for mobile, as I’ve been doing. Open VIII is a Final Fantasy VIII game engine written in C#/MonoGame and currently works on Windows and Linux (not sure about Mac). Other games in the series have been ported to other platforms but not FFVIII, so that’s why the project was started.

The instructions for Open VIII on Windows suggest Visual Studio 2017 but I imagine 2019 might also work as MonoGame 3.8 has templates for it.  As the project says “OpenVIII is an open-source complete Final Fantasy VIII game engine rewrite from scratch powered in OpenGL making it possible to play the vanilla game on wide variety of platforms including Windows 32/64 bitLinux 32/64 bit and even mobile!

As with virtually all open source reimplementations, you will have to provide your own game assets such as images and sound. You can do this apparently by buying the original game on Steam. I took a look and sure enough it’s there and there’s an official remastering by Square Enix. I’m not sure why the Steam search brings up FF VII as well but hey that’s search for you… I’ve added a permanent link to the C#/MonoGame links page.

Steam Final Fantasy VIII

How to install WSL 2 and Linux on Windows 10

How to install WSL 2 and Linux on Windows 10

Winver commandThis assumes that you have the version 2004 of Windows 10. Run the command Winver (open a command line then type winver) to see what version you have.

WSL is Windows Subsystem for Linux and lets you run one of several Linuxes (after installing) in Windows. For now it is terminal only but you can debug programs using Visual Studio. WSL 2 is the current version of WSL though you can run the older WSL 1.

Your computer also needs to support Hyper-V Virtualization to run WSL 2. If it doesn’t you can run WSL 1.

Steps.

  1. Open a PowerShell windows in Admin mode. My way of doing this is open the search window and type Powershell. Then right-click run as Admin.

 

When I mean Search Window, I mean the one on the Toolbar that looks like this like a magnifying glass: (highlighted in the red square)

Search Window

 

 

2. In the Powershell Windows, copy and paste this command:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

3. Next run this command in the same Windows:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

4. Set WSL 2 as default with this Powershell command:

wsl --set-default-version 2

Now close the Powershell Window and in the search box type Store. You should see Microsoft Store.  It’s an app on your PC. Click it to run it and type in Linux in the search box. Click Show all and you should see something like this. Pick one like Ubuntu, Debian etc.  Apart from the ones with a price against them, the rest are free. Cl;ick Get and it will install.

Linux in Microsoft Store

After it has installed, you can run it from your Start Menu. I dragged it onto the square so I have a nice clickable icon.

Windows Start MenuJust click it and your Ubuntu (or whatever) Linux will open at a terminal prompt like this.

Ubuntu Terminal

 

Space Invaders done faithfully in C

Space Invaders done faithfully in C

Si78 Space InvadersI was around when space invaders came out in the late 70s and played it a bit, although I preferred Galaxian, Gorf, Defender and Battle Zone (3D Tanks on the moon- vector graphics).

This project (catchily named si78) though is a memory accurate re-implementation of the 1978 arcade game Space Invaders in C.

To build and run this (on a Linux box) you’ll need to download the invaders ROM which is available in one of the Mame sets. The game is written in the subset of C99 that is compatible with C++, and uses no compiler extensions apart from attribute packed.

 

On apt vs apt-get

On apt vs apt-get

Linux
Image by Donald Clark from Pixabay

This is the command you use to update your system, fetch and install software. Some people use apt-get, others plain apt and the two appear interchangeable but they are NOT the same. As it’s making a change to the system, you almost always have to run it via sudo.

They are different?

Well yes. Try these.

apt --help

apt-get --help

Those give different help messages. And as for these:

apt check

apt-get check

It’s curious that apt-get check works, but apt check gives an invalid operation! I’m not sure why they are so similar yet subtly different. If anyone knows, drop me a line.

Having created this post, I subsequently did find out the differences- explained on this page. The simplified version is the apt is a simpler subset and also shows a progress bar when you do sudo apt upgrade. Try sudo apt-get upgrade next time to see it without the progress bar!

 

Here’s the Raspberry Pi temperature code

Here’s the Raspberry Pi temperature code

To add temperature to the frame caption, I first do a check to see that it is running on a Raspberry Pi. This function does that.

void SetPiFlag() {
	struct utsname buffer;
	tempFlag = 0;
    if (uname(&buffer) != 0) return;
    if (strcmp(buffer.nodename,"raspberrypi") !=0) return;
	if (strcmp(buffer.machine,"armv7l") != 0) return;
	piFlag=1;
}

Note you have to add this include

#include <sys/utsname.h>

Now you need to call this function to return the temperature as a float.

float ReadPiTemperature() {
    char buffer[10]; 
	char * end; 
	if (!piFlag) return 0.0f;
	if (SDL_GetTicks() - tempCount < 1000) {	
		return lastTemp;
	}
	tempCount = SDL_GetTicks() ;
	FILE * temp = fopen("/sys/class/thermal/thermal_zone0/temp","rt"); 
	int numread = fread(buffer,10,1,temp); 
	fclose(temp); 
	lastTemp = strtol(buffer,&end,10)/1000.0f;
	return lastTemp;
}

Things to notice.

  1. If it’s not running on a Pi it always returns 0.0C.
  2. No matter how often it’s called, it only reads the temperature once a second.
  3. In between reads it caches the temperature in a variable lastTemp

When I first wrote this, it was reading the temperature on every frame. It actually changes that quickly but that made it hard to read. So once a second is fine.