cross-compile for ARM64, understanding make TARGET=aarch64 - gcc

I'm trying to cross-compile a library for ARM64, I'm using Ubuntu 18.04 x86_64 host system for a build
and the way I'm doing the cross-compile as
sudo apt-get update
sudo apt-get install crossbuild-essential-arm64
and do the make
make -j 4 TARGET=aarch64
wonder what a compiler is invoked? Is it possible to set the latest gcc from ARM?
FYI. I'm trying to follow TensorFlow cross-compile for ARM64 and set the latest GNU Toolchain for ARM64.

Related

How to build an application for both architectures depending on some external library OR to install library for both architectures?

I have a Mac which architecture is:
$ arch
arm64
(it supports x86_64 and aarch64).
And I have installed openssl library with brew tool. Now I try to build my application for x86_64 platform (it's Haskell application and the build script is large and complex, so I cannot show it here) and I get an error:
...
<command line>: dlopen(/MyWork/.stack/snapshots/x86_64-osx/b1d675598b9b6c5f516e03f82c45d01becd6003e6128005b2b4acb8628b0f350/9.2.5/lib/x86_64-osx-ghc-9.2.5/libHSHsOpenSSL-0.11.7.2-1JX1qBi8YfpGDjk1ra3OXq-ghc9.2.5.dylib, 0x0005): symbol not found in flat namespace '_DSA_free'
...
However, it works fine for aarch64 platform. After little research I see that my OpenSSL libraries are:
$ file /opt/homebrew/opt/openssl#3/3.0.7/lib/libssl.3.dylib
/opt/homebrew/opt/openssl#3/3.0.7/lib/libssl.3.dylib: Mach-O 64-bit dynamically linked shared library arm64
which seems that it is a library for arm64 and not x86_64, so maybe this is the reason of the error "symbol not found in flat namespace '_DSA_free'".
How to fix it? I guess I need to install the second openssl - for x86_64, I tried arch -x86_64 brew install openssl but I get:
Warning: openssl#3 3.0.7 is already installed and up-to-date.
To reinstall 3.0.7, run:
brew reinstall openssl#3
which makes sense - it is installed already (but for arm64).
How to fix/workaround this problem, so to be able to build the application for both platform while it depends on external libraries like openssl? Maybe there is a way to install openssl for both platform?
EDIT:
Currently I found 2 solutions:
to install libraries from sources setting prefix=/unique/folder/for/arch and to prefix ./configure ..., make, make install by arch -ARCH (where ARCH is x86_64 or arm64).
Another way is to have 2nd Homebrew, it's described here

Compiling gRPC on MacOS for Darwin ARM64 - using bazel or cmake instead of make

OS: MacOS 11
Platform: Apple M1 architecture (Darwin ARM64)
According to
https://chromium.googlesource.com/external/github.com/grpc/grpc/+/HEAD/BUILDING.md
using make is outdated.
I downloaded and installed bazel Darwin x64 (MacOS Intel) binary latest version, bazel build :all completed without errors.
bazel test --config=dbg //test/... however prints out a lot of errors after a few minutes of compiling.
There's also the option to run cmake, which also completes.
So, my question is, am I correct if cmake or bazel (with build :all, of course) does not install the binaries, but rather make and (sudo) make install do?
If the use of make is "outdated", is bazel / cmake used to install the compiled binaries?

GCC cross compilation tool for fedora

I need to compile a code with gcc for ARMv7-A architecture on x86 system, how can i install tools on fedora??
gcc-arm-linux-gnueabi package is not available in fedora and sudo dnf install gcc-arm-linux-gnueabi did not work.
Arm provides prebuilt GNU cross-toolchains which is available from developer.arm.com.
For A-profile cores - https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a
For R and M profile cores - https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm.
Hope that helps.

Cross compile windows 64 bit .exe from linux

I know that if I want to compile a 32 bit .exe for windows on Linux I can just install and use the mingw32 package (e.g. apt-get install mingw32) on linux. What if I want to compile a windows .exe that is 64 bit? Is there tools or a method to do this?
It looks like my answer lies with the Mingw-w64 project which is available for host OSes Linux, Darwin & Windows
I know this question is very old and already has an accepted answer but I will post this answer the way I do it now. It is pretty simple and straightforward and I hope it helps anyone landing here:
To cross-compile windows applications from a Linux machine you just need to install mingw-w64 C and C++ compiler. On debian based system you just do this:
sudo apt install -y gcc-mingw-w64 g++-mingw-w64
That will install the gcc (the c compiler) and g++ (the c++ compiler) for both 64 and 32 bit cross-compilation
After that, if you need a 64-bit application just do:
x86_64-w64-mingw32-g++ hello.c -o hello.exe
And if you need a 32-bit application just do:
i686-w64-mingw32-g++ hello.c -o hello.exe
Simple as that!
It's also possible to install MinGW from MSYS2. The main advantages are:
Usually up-to-date MinGW, regardless of what your Linux distribution ships.
A lot of prebuilt libraries.
Several MinGW flavors are provided: x32 and x64, with different C runtimes, etc.
You can't install MSYS2 on Linux directly, but it's possible with Quasi-MSYS2.
Install Clang (and LLD):
On Ubuntu:
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh
rm llvm.sh
Clang can cross-compile to Windows using MSYS2 libraries. Alternatively, you can run MSYS2 MinGW in Wine, but it's slower.
Install dependencies:
sudo apt install make wget tar zstd gpg wine
Wine is optional.
Install Quasi-MSYS2 and any desired MSYS2 packages:
git clone https://github.com/HolyBlackCat/quasi-msys2
cd quasi-msys2/
# Optionally, choose MSYS2 flavor, see full list at: https://www.msys2.org/docs/environments/
# echo MINGW64 >msystem.txt
make install _gcc _gdb
Then:
env/shell.sh opens a shell with the correct environment variables set up.
win-clang++ hello.cpp invokes Clang with flags for cross-compilation.
./a.exe runs the resulting app in Wine, if it's installed.
Full disclosure: I'm the developer of quasi-msys2.

How can I easily install arm-elf-gcc on OS X?

Please let me know if this should be on Server Fault...
I've got some code I want to compile which requires arm-elf-gcc. I'm not an embedded programmer, so all this is new to me. My development machine is a Mac and I use fink pretty often, so I'd love to be able to install it that way. However, fink doesn't know of any package with that name. I see that gnuarm.org has some binaries for OS X but their packages seem to also include a bunch of stuff (e.g. gcc) I already have. Am I correct in believing that I need to install binutils, newlib and a file called t-arm-elf?
MacPorts supports arm-elf-gcc.
$ port search arm-elf
arm-elf-binutils #2.20.51.0.2 (cross, devel)
FSF Binutils for arm-elf cross development
arm-elf-gcc #4.3.2 (cross, devel)
gcc cross-compilers for arm-elf, with newlib runtime library.
arm-elf-gcc3 #3.4.6 (cross, devel)
gcc 3.x cross-compilers for arm-elf, with newlib runtime library.
Found 3 ports.
Once you install MacPorts, all it would take is:
$ sudo port install arm-elf-gcc

Resources