Easiest way to compile a core for arm 32bit inside Linux?

I am trying to compile a core for my arm linux handheld, namely newer hatari core than it has and can’t get it to work. That has a cortex-a7 32bit SoC. I even tried to compile lakka but that looks like it does a ton of compiling. Tried compiling “package” of hatari for a 32bit arm “project” but it looks like it compiles lots and lots more than just my core. There has to be an easier way, like passing some parameter to libretro.build.sh

do you have a cross-compiling toolchain set up? If so, you can usually just go into the core’s source tree and run ‘make’ and call out the cross-compiler with CC/CXX flags.

In my opinion, the easiest way to cross compile is with a Debian machine or Docker image (slightly older than the lakka version, so glibc is not an issue). For arm install the following package (assuming hardfloat):

crossbuild-essential-armhf

If the core is simple and does not need any other dependencies, then as hunterk says the command to build would generally be something like this:

CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ make -f (libretro makefile) platform=something

where the libretro makefile and platform varies, you would have to inspect the source to determine the appropriate parameters.

All that said, it is worthwhile to build a package with the lakka build system to use the official toolchain.

2 Likes

I edited the hatari Makefile.libretro a bit added CC, AR, CXX, PKG_CONFIG_PATH

got the idea from here

# (armv7 a7, hard point, neon based) ### 
# NESC, SNESC, C64 mini 
else ifeq ($(platform), classic_armv7_a7)
	TARGET := $(TARGET_NAME)_libretro.so
	fpic := -fPIC
	SHARED :=  -lz -lpthread -shared -Wl,--version-script=$(LIBRETRO_DIR)/link.T -Wl,--no-undefined
	CC=/usr/bin/arm-linux-gnueabihf-gcc
	AR=/usr/bin/arm-linux-gnueabihf-gcc-ar
	CXX=/usr/bin/arm-linux-gnueabihf-g++
	PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig/
	CFLAGS += -Ofast \
	-fdata-sections -ffunction-sections -Wl,--gc-sections \
	-fno-stack-protector -fno-ident -fomit-frame-pointer \
	-falign-functions=1 -falign-jumps=1 -falign-loops=1 \
	-fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops \
	-fmerge-all-constants -fno-math-errno \
	-marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
	HAVE_NEON = 1
	ARCH = arm

	PLATFLAGS := -DLSB_FIRST -DALIGN_DWORD
	ifeq ($(shell echo `$(CC) -dumpversion` "< 4.9" | bc -l), 1)
	  CFLAGS += -march=armv7-a
	else
	  CFLAGS += -march=armv7ve
	  # If gcc is 5.0 or later
	  ifeq ($(shell echo `$(CC) -dumpversion` ">= 5" | bc -l), 1)
	    LDFLAGS += -static-libgcc -static-libstdc++
	  endif
	endif

then run

$ make -f Makefile.libretro platform=classic_armv7_a7

and it compiles up to a point and i get

/usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lz
/usr/lib/gcc-cross/arm-linux-gnueabihf/10/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lz
collect2: error: ld returned 1 exit status

From same github i did what it proposed for docker, it builds one hour. Then i cannot understand how to run

sudo docker run --rm -it -v "<cloned dir>:/build" <image name>

Did you get the image built successfully? Those are old distributions (on purpose, so that there will be no surprised when trying to run it on a possibly older system), so there may be some problems retrieving the packages.

After building, docker should return an image ID. You can check it later: sudo docker images. You can use the ID in the docker run command, or tag it to something friendlier.

The link error probably refers to libz. Cores may need some libraries, which need to be installed separately due to the different architecture, something that has both libzstd1 (?) and “armhf” in the name.

ok so i got

REPOSITORY                                                                  TAG           IMAGE ID       CREATED         SIZE
<none>                                                                      <none>        cc2163c190cd   45 hours ago    2.86GB
<none>                                                                      <none>        dc5771492cb1   45 hours ago    6.86GB
hello-world                                                                 latest        d2c94e258dcb   17 months ago   13.3kB
git.libretro.com:5050/libretro-infrastructure/libretro-build-amd64-ubuntu   xenial-gcc9   b830cf100bbd   2 years ago     1.97GB
ubuntu

i guess i should use something like

sudo docker run --rm -it -v "libretro-cap32:/build" dc5771492cb1

?

Done, i did it, compiled latest libretro hatari with your instructions for docker. Awesome, runs perfectly on Miyoo A30

sudo docker run --rm -it -v "/home/dariusg/Downloads/libretro-super:/build" cc2163c190cd

then “build” contains the folder (libretro super), a walk in the park to fetch and build

1 Like