Can anyone help compile a .so file for arm64 by editing the cmake files? #1600
Replies: 8 comments 2 replies
-
Could you advise @galabovaa ? |
Beta Was this translation helpful? Give feedback.
-
@benjaminplong Are you intending to cross-compile (e.g., build for an ARM target on x86_64) or do you have access to an ARM machine that you can natively compile on? If you can natively compile, it should "just work" without any need for modification to the cmake build system. If you are hoping to cross-compile, there could be some easy answers depending on your build environment -- having a description of your build environment (platform, OS, etc.) could be useful |
Beta Was this translation helpful? Give feedback.
-
Additionally, we are working to clean up and improve the CMake build, coming soon with the updated highspy! |
Beta Was this translation helpful? Give feedback.
-
@mckib2 I am trying to cross-compile from a x86_64 Linux environment to an arm64v8 Linux environment. |
Beta Was this translation helpful? Give feedback.
-
@benjaminplong I got this working on Ubuntu x86_64: # install cross-compiler toolchain
sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu
# build HiGHS using cross-compiler
mkdir build && cd build
cmake \
-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
-DFAST_BUILD=OFF \
-DZLIB=OFF \
-DSHARED=OFF \
..
make -j
# Notes:
# - The following options could go into a toolchain file, but I found it easy enough to add as cmake options:
# CMAKE_C_COMPILER, CMAKE_CXX_COMPILER, CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_PROCESSOR
# - HiGHS options:
# FAST_BUILD: turned off to get the option to build static libraries instead of shared
# ZLIB: cmake was picking up my x86_64 version of the zlib libraries, so I turned it off. You could probably install the aarch64 versions and it would be fine to leave on
# SHARED: linker was picking up my x86_64 versions of the std lib, etc., so I changed to building static libraries. You could probably install the aarch64 versions of the shared libraries and it would be fine to build shared. I tested like this: # get an aarch64 emulator
sudo apt install qemu-user qemu-user-static
# run tests using emulator
qemu-aarch64 -L /usr/aarch64-linux-gnu/ bin/unit_tests Curiously I got 1 failure: -------------------------------------------------------------------------------
LP-solver
-------------------------------------------------------------------------------
HiGHS/check/TestLpSolvers.cpp:229
...............................................................................
HiGHS/check/TestLpSolvers.cpp:282: FAILED:
REQUIRE( info.simplex_iteration_count == 472 )
with expansion:
437 (0x1b5) == 472 (0x1d8)
===============================================================================
test cases: 186 | 185 passed | 1 failed
assertions: 1253705 | 1253704 passed | 1 failed It's not an important failure it looks like -- just looks like the simplex method took fewer iterations than expected to solve a problem on aarch64 compared to x86_64. |
Beta Was this translation helpful? Give feedback.
-
Maybe I need the shared libraries you mentioned? I need to produce a .so object for my purposes. |
Beta Was this translation helpful? Give feedback.
-
In my experience, CentOS/RHEL distros (of which RockyLinux is trying to be like) are really hard to cross compile on as I believe they don't allow installation of foreign architecture packages (e.g., installing aarch64 packages on x86_64 platforms). Is there a chance you can switch to a Debian-based distro or is your heart set on RockyLinux? I'll try to give it a go, but it will likely get really messy and I'm not confident I'd be able to get working binaries |
Beta Was this translation helpful? Give feedback.
-
@benjaminplong Here's my best attempt. It seems to produce binaries, but I was unable to verify they work as you can't run QEMU inside of Docker. If you get this building, I'd be curious to know if the libraries work on the target ARM device. I pulled the latest RockyLinux Docker image and used This method is also able to produce the shared libraries without needing to hunt down any other dependencies as cd /path/to/HiGHS
docker pull rockylinux:9.3
docker run -it -v $(pwd):/src rockylinux:9.3 /bin/bash
$ yum update -y
$ yum install -y epel-release
$ yum repolist
$ dnf config-manager --set-enabled crb
$ yum install -y autoconf automake which flex bzip2 xz unzip help2man file patch libtool bison ncurses-devel gcc gcc-c++ diffutils cmake make texinfo-tex git python3-devel
$ cd /tmp
$ git clone https://github.com/crosstool-ng/crosstool-ng
$ cd crosstool-ng
$ ./bootstrap
$ ./configure --enable-local
$ make -j
$ ./ct-ng aarch64-unknown-linux-gnu # there are other configurations, run `./ct-ng list-samples` to see all possible options
# may want to customize this futher via `./ct-ng menuconfig` -- I enabled experimental features to run ./ct-ng build as the default Docker root user
# By default, everything was installed into `/root/x-tools/` for me, but it may be dependent on user. This is configurable via `./ct-ng menuconfig`.
$ ./ct-ng build # this will take some time to download and build everything
# I needed to run this for some reason -- could be some Docker shenanigans, so you may not need to
$ git config --global --add safe.directory /src
$ cd /src
$ mkdir build && cd build
$ cmake \
-DCMAKE_C_COMPILER=/root/x-tools/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc \
-DCMAKE_CXX_COMPILER=/root/x-tools/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-g++ \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=aarch64 \
..
$ make -j |
Beta Was this translation helpful? Give feedback.
-
I have generated a .so file that works for x86_64 Linux, but now I need an arm version that will also run on Linux. I am not very experienced with CMake so I'm hoping someone here can help me. Thank you.
Beta Was this translation helpful? Give feedback.
All reactions