Links mentioned in the video:
- Click here to join the KC Amiga Corner, and support Amiga software creation
- Set up your own AmigaOS cross compiler
- Copying cross-compiled files to your Amiga
Summary
In brief, here’s how to build a raylib app for AmigaOS4 using a cross-compiler.
Obviously, you’ll need an AmigaOS4 cross-compiler. The easiest option is to use a ready made docker container, as per this video. You can use the template from that video as a starting point. Remove the original source file and makefile, and replace it with your raylib app’s code.
I used a hello_raylib example from my book, The CMake Tutorial as starting point. It’s a minimal example that’s perfect for getting our first raylib app running on AmigaOS 4. Here’s the source code:
#include "raylib.h"
#include <cstdlib>
int main(int argc, const char **argv) {
// Initialization
const int screenWidth = 1280;
const int screenHeight = 768;
const char *windowTitle = "Hello world!";
const char *message = "Hello world! It's great to be here.";
const int fontSize = 40;
const float msgSpacing = 1.0f;
InitWindow(screenWidth, screenHeight, windowTitle);
// NOTE: The following only works after calling InitWindow() (i.e,. RayLib is initialized)
const Font font = GetFontDefault();
const Vector2 msgSize = MeasureTextEx(font, message, fontSize, msgSpacing);
const Vector2 msgPos = Vector2{(screenWidth - msgSize.x) / 2, (screenHeight - msgSize.y) / 2};
SetTargetFPS(60);
// Main loop
while(!WindowShouldClose()) {
// Update the display
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTextEx(font, message, msgPos, fontSize, msgSpacing, RED);
EndDrawing();
}
// Cleanup
CloseWindow();
return EXIT_SUCCESS;
}
Raylib’s AmigaOS port still has rough edges, so we can’t build it as easily as on other platforms. In particular, we have to manually install dependencies. Andrea Palmate has made this relatively easy by creating some Linux packages. So everything is an apt install away. Here’s how it’s done…
First, you need to log into the docker container as root user to install packages. So open .devcointainer/devcontainer.json, and change “remoteUser” from “amidev” to “root.” Restart the container.
Now you can add the clib4 package repository, and install the dependencies. Execute the following in the terminal window:
curl -fsSL https://clib4pkg.amigasoft.net/ubuntu/clib4.gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/clib4.gpg
echo "deb https://clib4pkg.amigasoft.net/ubuntu/ focal main" | sudo tee /etc/apt/sources.list.d/clib4.list
apt update
apt install amigaos4-clib4 libraylib5-clib4 opengles-clib4 libgl4es-clib4
You may wish to change “remoteUser” back to “amidev” for security pursposes. However do NOT click the “rebuild” button when VS Code asks you if you want to rebuild the container! This will reset the docker container, wiping everything that you just installed. Instead, restart the container. If you don’t know how, then just close VS Code, and restart it.
Now we need to tweak the CMakeLists.txt build script. FetchContent won’t work for us, so we drop down to find_package(). Here’s the new build script:
cmake_minimum_required(VERSION 3.22)
project(hello_raylib)
# Workaround for CLang and RayLib's compound literals
# See: https://github.com/raysan5/raylib/issues/1343
set(CMAKE_CXX_STANDARD 11)
# NOTE: I'd prefer to use FetchContent, but building Raylib on AmigaOS 4 is currently too messy.
# Please run the script install-aos4-deps.sh
set(GLFW_VERSION 3)
set(RAYLIB_VERSION 5.5.0)
find_package(raylib ${RAYLIB_VERSION} REQUIRED)
find_package(glfw3 ${GLFW_VERSION} REQUIRED)
find_package(OpenGL REQUIRED)
find_package(Threads REQUIRED)
# Our Project
set(SOURCE_FILES
Main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} raylib glfw3 GL Threads::Threads)
One more step before we can build the program: CMake needs to be told to use the cross-compiler instead of the regular compiler. Doing this from the command line would be tedious, so we create a toolchain file called amigaos4-cross.cmake:
# Toolchain file for cross-compiling to AmigaOS 4
set(CMAKE_SYSTEM_NAME AmigaOS)
set(CMAKE_SYSTEM_VERSION 4)
set(CMAKE_SYSTEM_PROCESSOR "powerpc")
set(AMIGAOS4 1)
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
# specify the cross compiler
set(CMAKE_C_COMPILER ppc-amigaos-gcc)
set(CMAKE_CXX_COMPILER ppc-amigaos-g++)
set(CMAKE_CXX_FLAGS "-mcrt=clib4 -mstrict-align")
set(CMAKE_C_FLAGS "-mcrt=clib4 -mstrict-align")
set(CMAKE_LD_FLAGS "-mcrt=clib4 -athread=native")
set(CMAKE_EXE_LINKER_FLAGS "-mcrt=clib4 -Wl,--no-undefined -athread=native")
set(CMAKE_SHARED_LINKER_FLAGS "-mcrt=clib4 -use-dynld -Wl,--no-undefined -athread=native ")
set(CMAKE_INSTALL_PREFIX /usr/ppc-amigaos/SDK/local/clib4)
set(CMAKE_MODULE_LINKER_FLAGS -shared)
set(CMAKE_SHARED_LINKER_FLAGS -shared)
# Where to find packages such as raylib
set(CMAKE_PREFIX_PATH /opt/ppc-amigaos/ppc-amigaos/SDK/local/clib4)
include_directories(/opt/ppc-amigaos/ppc-amigaos/SDK/local/common/include)
set(OPENGL_INCLUDE_DIR ${CMAKE_PREFIX_PATH}/include)
This sets up the compiler, compile and linker flags, and tells CMake where it can find the installed packages and header files. Now we can build our hello_raylib program in the terminal as follows:
cmake -B build --toolchain amigaos4-cross.cmake .
cmake --build build --parallel
It’s built. Now copy it to your Amiga computer for testing (e.g., as per this video). And, it works!

Good, but not Great
While it’s great to see it working, I’m not satisfied for three reasons:
- The build script is AmigaOS-specific, and I need something that will build on multiple platforms. This it the only way that I can afford to write software for the Amiga at present, aside from the drivers that I work on for A-EON
- I hate manual dependency installation. While I don’t have to go chasing down dependencies one-by-one, I want this to build out-of-the-box
- As an Amiga computer fan, it’s very unsatisfying that I can’t build the app natively, on AmigaOS itself. I did try, and it almost worked. However, there was one bug in our CMake port that I simply couldn’t overcome
There’s good news, though. I submitted bug reports and the AmigaLabs team are working on fixing the problems. So I expect that we will be able to build this code on AmigaOS natively within the next few months.
Next Steps
For my part, I’m going to work on a raylib project template that will compile out-of-the-box on all platforms including AmigaOS. This will replace the current raylib on AmigaOS template, which Creator and higher tier members can download inside the Kea Campus’ Amiga Corner..
Support Amiga Software & Content
If you want to support my Amiga work, then join the Kea Campus’ Amiga Corner. You’ll get the source code for not only this video, but all previous videos too. And, a lot more (e.g., the Saving AmigaOS series). Plus, you’ll be helping me to keep creating software & videos for the Amiga computer…