libbpf-bootstrap icon indicating copy to clipboard operation
libbpf-bootstrap copied to clipboard

How to cross-compile programs from amd64 to arm64

Open bartsmykla opened this issue 2 years ago • 6 comments

I'm trying to cross-compile some of the programs built on top of libbpf-bootstrap, but I'm lacking expertise with C/C++ ecosystem. I see that support for cross-compilation was added in https://github.com/libbpf/libbpf-bootstrap/commit/7b60b4fd6c6da6af046dc6f618c771f763b6a472 I would appreciate help with:

  • what are the packages I have to have installed on Ubuntu 22.04 (amd64) to cross-compile programs to arm64?
  • do I have to cross-compile libelf and zlib first? If so, any hints how can I do it?

My current results:

~ CROSS_COMPILE=aarch64-linux-gnu-g make all
  BINARY   bind
/usr/lib/gcc-cross/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/bin/ld: cannot find -lelf: No such file or directory
/usr/lib/gcc-cross/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/bin/ld: cannot find -lz: No such file or directory

bartsmykla avatar Feb 20 '23 11:02 bartsmykla

@wangjie could you please help? I'm not very familiar with cross-compilation, unfortunately.

anakryiko avatar Mar 08 '23 17:03 anakryiko

I'm trying to cross-compile some of the programs built on top of libbpf-bootstrap, but I'm lacking expertise with C/C++ ecosystem. I see that support for cross-compilation was added in 7b60b4f I would appreciate help with:

  • what are the packages I have to have installed on Ubuntu 22.04 (amd64) to cross-compile programs to arm64?
  • do I have to cross-compile libelf and zlib first? If so, any hints how can I do it?

My current results:

~ CROSS_COMPILE=aarch64-linux-gnu-g make all
  BINARY   bind
/usr/lib/gcc-cross/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/bin/ld: cannot find -lelf: No such file or directory
/usr/lib/gcc-cross/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/bin/ld: cannot find -lz: No such file or directory

Hi bartsmykla, Yes, libbpf depends on libelf and libz, so you need declare where the libraries and header files can be found. such as, make EXTRA_CFLAGS="-IXXX" EXTRA_LDFLAGS="-LXXX" ARCH=arm64. You can get a copy of these libraries from here for quickly verification if you don't want to cross-compile them yourself.

setNull avatar Apr 26 '23 03:04 setNull

the same here,thanks

JiaHuann avatar Aug 21 '23 15:08 JiaHuann

libbpf-bootstrap-android x86 -> android aarch64. I embbed deps and add externel path to involve BTF file for android kernel,wish this can help you.

JiaHuann avatar Aug 31 '23 03:08 JiaHuann

can you submit a clear PR with only necessary changes?

anakryiko avatar Sep 14 '23 21:09 anakryiko

can you submit a clear PR with only necessary changes?

Ok,I will do it recently.

JiaHuann avatar Sep 20 '23 08:09 JiaHuann