Issues with compiling ARM binary for STM on Apple MAC book - c

I am trying to compile a project on Mac but I am getting lots of errors. It compiles fine on Linux. I reference the toolkit included with STM workshop.
When running cmake ../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../../tools/toolchain/nucleo_f746zg.cmake from /build/debug, I get the following output..
/var/folders/fg/ldkpxwvn45v5y854s4zsw_b00000gn/T//ccBDWJKO.s:404: Error: selected processor does not support `dsb' in ARM mode
/var/folders/fg/ldkpxwvn45v5y854s4zsw_b00000gn/T//ccBDWJKO.s:407: Error: selected processor does not support `isb' in ARM mode
make[2]: *** [platform/nucleo-f746zg/CMakeFiles/alesi-platform-nucleo-f746zg.dir/osal/freertos/os_context.c.obj] Error 1
make[1]: *** [platform/nucleo-f746zg/CMakeFiles/alesi-platform-nucleo-f746zg.dir/all] Error 2
make: *** [all] Error
Does anyone have advice for this? How can I compile the code for ARM?
I am running ARM GNU tools and using arm-none-eabi-g++ and arm-none-eabi-gcc compilers.

The STM32 family of microcontrollers is based on Cortex cores, they're not able to run ARM instructions set, they use Thumb-1 and Thumb-2.
For the STM32F4 family I use flags like -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16.
The readme.txt from gcc-arm-embedded can give you some hints on how to select the most appropriate flags for your target architecture.

If you are a beginner just install a ready made IDE with toolchain. Google for openSTM32. It is an eclipse + plugins + toolchain.
It will save you many days of googling and configuring

Related

concorde with Apple Silicon M1

I am trying to install concorde linked with QSOPT following these instructions. Regarding QSOPT, I dowloaded files from section Intel MacOS 10.6 (64-Bit). But, as I have Apple M1 chip, it does not work. I think that the problem is in the arm64 architecture in terms of QS, however with other more commercial software for Intel processor, I do not face any issue thanks to Rosetta.
The error I am facing when I run
./configure --host=darwin --with-qsopt=fullpath/QS
is
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [concorde] Error 1
Cross-posted on Stack Exchange - Operation Research
Thanks to the support of Bill Cook, it is now available a version of qsopt.a for the M1 Apple Chip on the QSOPT download page. This perfectly worked for me by run
./configure --host=darwin --with-qsopt=fullpath/QS

Installing Tensorflow Lite with CMake

I am trying to install Tensorflow Lite on Raspberry Pi Zero W. I followed the steps from the official website (https://www.tensorflow.org/lite/guide/build_cmake_arm). But I get the following error message:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: /home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc
-- Check for working C compiler: /home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
The C compiler
"/home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/make cmTC_ed1a3/fast && /usr/bin/make -f CMakeFiles/cmTC_ed1a3.dir/build.make CMakeFiles/cmTC_ed1a3.dir/build
make[1]: Entering directory '/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_ed1a3.dir/testCCompiler.c.o
/home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc -march=armv6 -mfpu=vfp -funsafe-math-optimizations -o CMakeFiles/cmTC_ed1a3.dir/testCCompiler.c.o -c /home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp/testCCompiler.c
/home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc: 1: /home/pi/toolchains/arm-rpi-linux-gnueabihf/x64-gcc-6.5.0/arm-rpi-linux-gnueabihf/bin/arm-rpi-linux-gnueabihf-gcc: Syntax error: ")" unexpected
make[1]: *** [CMakeFiles/cmTC_ed1a3.dir/build.make:66: CMakeFiles/cmTC_ed1a3.dir/testCCompiler.c.o] Error 2
make[1]: Leaving directory '/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeTmp'
make: *** [Makefile:121: cmTC_ed1a3/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:44 (project)
Configuring incomplete, errors occurred!
See also "/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeOutput.log".
See also "/home/pi/Project/cmake-3.16.0/CMakeFiles/CMakeError.log".
Does anyone know how to fix the problem?
I ran into the same problem like you!
The instructions given at https://www.tensorflow.org/lite/guide/build_cmake_arm?hl=en are not intended to be executed on the Raspberry Pi (at least the last ones).
Let me share, what I'll figured out.
Short answer:
you're trying to run a cross-compile of TensorFlow Lite for an ARM made for x86 platform on an ARM system (your Raspberry Pi). What you're trying to do actually needs to be done on an x86 platform.
(on the top of the tutorial page is a hint: "following instructions have been tested on Ubuntu 16.04.3 64-bit PC (AMD64)" which reveals that the commands have been run on x86)
Some details:
The message ‘Syntax error: "(" unexpected’ probably comes from a shell. Why is a shell trying to execute your binary? Because the kernel tried and gave up. Why did the kernel fail to run the program? Because the executable is not in a supported format -> meant to be run on x86 but was executed on ARM.
https://unix.stackexchange.com/questions/336436/syntax-error-unexpected-when-execute-a-compiled-c-program
With older TensorFlow versions it was possible to compile TF lite on the Raspberry Pi itself via the
./tensorflow-2.4.1/tensorflow/lite/tools/make/download_dependencies.sh /and build_aarch64_lib.sh scripts.
However, this scripts got removed in version 2.8 (or even with an earlier version before). See note in the Readme of the Git: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/tools/make/README.md
Using Python for inference
Unfortunately I have no real solution how to compile / built TensorFlow Lite on the Raspberry itself. I personally ended up using Python (only needed inference) and followed this Tutorial:
https://qengineering.eu/install-tensorflow-2.7-on-raspberry-64-os.html

Issues wiith libssh cross-compilation for ARM

I am trying to cross compile libssh for ARM on a beaglebone black, following error happens when I run then 'make' command:
[ 52%] Linking CXX executable libsshpp_noexcept
../src/libssh.so.4.5.1: undefined reference to `deflateInit_'
I already run the cmake command with paths for libz and other arm gcc compiler paths, still facing the above error.
I was able to resolve this issue by rebuilding the correct arm version of zlib and re-installing it. Also using the ccmake GUI utility I removed the examples compilation which was creating other examples related errors. The correct installation of libssh requires, openssl, zlib, libzip all compiled for the same target arch as libssh.

ALSA Library and Cross Compiling for ARM

I'm trying to make an "C" application for my NXP(Freescale) imx6 that Debian OS installed on it. My host machine is Ubuntu 16.04. I'm using eclipse as an IDE and I can manage to cross compile until today. I use arm-linux-gnueabihf-gcc as an compiler and arm-linux-gnueabihf-ld as an linker. I added -lasound option to my linker parameter, but still can not build the application. I get an error
arm-linux-gnueabihf-ld: cannot find -lasound
I think I don't have the libasound.so file on my Ubuntu (Host) machine and my linker couldn't link to library to my application.
I copied the libasound.so file from my ARM machine to my host machine to the /home/user/Downloads folder, but still couldn't compile.
Is there a step to use ALSA library in Cross Compilation project before build?
Here is the output of build operation
Building target: tihc_linux_application
Invoking: GCC C Linker
/usr/bin/arm-linux-gnueabihf-ld -static -L/home/user/Downloads -pthread -lasound -o "main" ./src/main.o
/usr/bin/arm-linux-gnueabihf-ld: mode armelf_linux_eabi
/usr/bin/arm-linux-gnueabihf-ld: cannot find -lasound
You ask for static link (via -static) but provide shared library so ld probably ignores it (to be sure you can run with -Wl,--verbose). One option is to cross-compile libalsa from scratch and then use resulting static lib to link your app. Another option is to search for pre-compiled gnueabihf libalsa somewhere...

ARM cross compiling introduction?

I'm trying to compile a program to run on a Linux powered board, which has an ARM926EJ-S processor. So I've installed Debian embedded cross-development toolchain, and tried compiling an Hello World with in gcc with -march=armv5te . When I tried running the binary on the board it crashed with file not found errors (due to library versions), after that I've tried compiling with -static flag and I got a seg fault (0x0000827c in __libc_start_main (), said mr gdb trough gdbserver).
Any idea on what to do here to get something running?
Apparently the solution is to try as many toolchains as you can find. Eventually you'll find the one that works, after spending a few too many hours compiling toolchains. uClibc buildroot in this case.
You can find toolchains which support ARM926EJ-S on Linaro Page. Use the most recent arm-linux-gnueabi from Linaro project. I am currently using a version with gcc 4.9.4 which you can find here
It is recommended to use -mcpu=arm926ej-s instead of -march and -mtune. See gcc documentation because it combines -march and -mtune for your specified processor. It was deprecated for x86, but not for arm.
Other possibility could be building your own toolchain via crosstools-ng. But the Linaro toolchains are working out of the box if you don't need some specific setting (for example only using static libraries).

Resources