I have been searching for a while for cross-compile toolchain for this img am335x-eMMC-flasher-debian-11.7-iot-armhf-2023-09-02-4gb.img.xz but I didn’t find a significant result.
I have also tried to generate my own toolchain using cross-tool ng but the kernel version and the gcc, binutils and glibc versions were not compatible with the one in the img mentioned above.
In theory you can download one of the various Linaro compilers and set up your own sysroot for the Beaglebone. You can pass --sysroot=xxx to gcc and ld to set your custom sysroot.
You will then need to create your own sysroot on your host machine with the contents of /usr/include for the header files and the various lib directories. Use rsync to do this preserving symbolic links, but it should work if you don’t, it will just take up more space.
You will need to resync the files if you add new libraries that you need to link against or update existing libraries.
If building your own code this is probably not too hard. However if you are trying to cross compile a large project from someone else you are probably going to run into problems.
If you want a small image then you might be better off using Buildroot which will create a cross compiler with the correct sysroot. The difficulty of that will depend on just what you need. A default Buildroot compile for the BBB generates a very simple BusyBox environment using around 35M of space. Probably not what you need but a good starting point.