Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Steps for cross compiling linux-x64 to linux-armhf #677

Open
JonnyTech opened this issue May 2, 2024 · 2 comments
Open

Steps for cross compiling linux-x64 to linux-armhf #677

JonnyTech opened this issue May 2, 2024 · 2 comments

Comments

@JonnyTech
Copy link

JonnyTech commented May 2, 2024

Just a question: this seems a bit long winded, am I doing it correctly?

Version of fpcupdeluxe-x86_64-linux:

Welcome @ FPCUPdeluxe.
FPCUPdeluxe V2.4.0d for x86_64-linux-gtk2
Running on Debian GNU/Linux
Build with: FPC 3.2.3 on Win11 x86_64
CPU cores used: 8
Available physical memory: 7813 MB
Available swap: 0 MB

Current install directory: /home/user/development

Found crosscompiler for  arm-linux

Got settings from install directory.

Compiling to native works correctly:

$ cd /home/user/development/fpcsrc/packages/sqlite/tests/
$ /home/user/development/fpc/bin/x86_64-linux/fpc -n @/home/user/development/fpc/bin/x86_64-linux/fpc.cfg testapiv3x.pp
Free Pascal Compiler version 3.2.2-r0d122c49 [2024/05/01] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling testapiv3x.pp
testapiv3x.pp(3,2) Warning: APPTYPE is not supported by the target OS
Linking testapiv3x
87 lines compiled, 0.2 sec
1 warning(s) issued
$ file testapiv3x
testapiv3x: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.4.0, stripped

Cross compiling to linux-armhf (for Raspberry Pi):

$ /home/user/development/fpc/bin/x86_64-linux/ppcrossarm -n @/home/user/development/fpc/bin/x86_64-linux/fpc.cfg testapiv3x.pp
Free Pascal Compiler version 3.2.2-r0d122c49 [2024/05/01] for arm
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for ARMHF
Compiling testapiv3x.pp
testapiv3x.pp(3,2) Warning: APPTYPE is not supported by the target OS
Linking testapiv3x
/home/user/development/cross/bin/arm-linux/arm-linux-gnueabihf-ld: cannot find -lsqlite3
Error: Error while linking
Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

Ahh, ok, I need the `sqlite3 library files for armhf:

$ wget http://security.debian.org/debian-security/pool/updates/main/s/sqlite3/libsqlite3-0_3.27.2-3+deb10u2_armhf.deb
$ ar x libsqlite3-0_3.27.2-3+deb10u2_armhf.deb 
$ tar xvf data.tar.xz
$ cp ./usr/lib/arm-linux-gnueabihf/libsqlite3.so.0 libsqlite3.so
$ /home/user/development/fpc/bin/x86_64-linux/ppcrossarm -n @/home/user/development/fpc/bin/x86_64-linux/fpc.cfg testapiv3x.pp
Free Pascal Compiler version 3.2.2-r0d122c49 [2024/05/01] for arm
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for ARMHF
Compiling testapiv3x.pp
testapiv3x.pp(3,2) Warning: APPTYPE is not supported by the target OS
Linking testapiv3x
/home/user/development/cross/bin/arm-linux/arm-linux-gnueabihf-ld: ./libsqlite3.so: undefined reference to `fcntl64@GLIBC_2.28'
Error: Error while linking
Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

Hmm, do I need GLIBC_2.28? OK, it is at https://packages.debian.org/buster/libc6

$ wget http://security.debian.org/debian-security/pool/updates/main/g/glibc/libc6_2.28-10+deb10u2_armhf.deb
$ ar x libc6_2.28-10+deb10u2_armhf.deb
$ tar xvf data.tar.xz
$ cp -r ./lib/arm-linux-gnueabihf/* .
$ /home/user/development/fpc/bin/x86_64-linux/ppcrossarm -n @/home/user/development/fpc/bin/x86_64-linux/fpc.cfg testapiv3x.pp
Free Pascal Compiler version 3.2.2-r0d122c49 [2024/05/01] for arm
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for ARMHF
Compiling testapiv3x.pp
testapiv3x.pp(3,2) Warning: APPTYPE is not supported by the target OS
Linking testapiv3x
87 lines compiled, 0.2 sec
1 warning(s) issued
$ file testapiv3x
testapiv3x: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.0.0, stripped

File successfully built - yay! But were my steps necessary or is there an easier method?

@LongDirtyAnimAlf
Copy link
Owner

You did the right thing !
However.
Your app needs sqlite3. That library was not included into the cross-libraries as provided by fpcupdeluxe. So you used your own sqlite3.
However2.
Your sqlite3 library came from an older (or newer) linux version compared with the libs provided by fpcupdeluxe. So, your sqlite3 is not compatible with the other libraries.
If you feel lucky, you might try a tool that will allow you to use the libraries from your own target system.
https://github.com/LongDirtyAnimAlf/fpcupdeluxe/tree/master/fpcuptools/libraryscanner
Compile the libraryscanner on your target system. Run the command line version. It will create a directory with all libraries needed from your target system.

@JonnyTech
Copy link
Author

You did the right thing !

Thank you for the reassurance, that makes me feel better, I was very unsure.

Your sqlite3 library came from an older (or newer) linux version compared with the libs provided by fpcupdeluxe.

Out of interest, how did you know from the details that I provided?

If you feel lucky, you might try a tool that will allow you to use the libraries from your own target system.

Fantastic! I do not feel at all lucky, but I am always ready for learning and an adventure.

Compile the libraryscanner on your target system.

Can I cross-compile? I do not have a development environment on the current target system.

Ultimately, the final system shall be Ultibo, so there may be more challenges ahead for me...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants