Hello world does not compile with Makefile option in Torizon plugin

Hello,
I am using an Apalis iMX8 with the Ixora board.
I am trying to use the Torizon plugin in VSCode on Windows10 to build a basic Hello-world.

Tried both options from Create C/C++ application.
armv32-torizon
armv64-torizon

For the Hello.c program, clicking on Terminal → Run Build Task in VSCode generates 2 additional files as below.

  • Hello.o
    -Hello (without any extension)

I then click on New Terminal which takes me to the docker-desktop environment for this and try running the commands.
./Hello
./Hello.o

I have also used chmod ugo+x on both these files to make them executable.
However, I am getting errors.
For ./Hello
No such file or directory.

For ./Hello.o
cannot execute binary file: Exec format error.
Attaching a screenshot accordingly.
Please can you let me know why this option is not working. I need to compile more advanced programs using the Makefile option.

Hi @SJ_BHD ,

The error message is expected, because the SDK container that builds the application is actually x86_64: You can check this by running uname -r in a new terminal inside the container. It uses cross-compilation to build your project.

That’s why you’re seeing the exec format error when trying to run the Hello binary, which was built to run on Arm64 (the ISA for iMX8).

If you want to test your application you can deploy a container with it to your Apalis iMX8. You can see more details on how to do that in this article: Visual Studio Code Extension for Torizon | Toradex Developer Center.

Let me know if this helps you.

Best regards,
Lucas Akira

Thanks Lucas,
I was able to deploy the application using those instructions.
Also the release image deployed on the board did run when invoked, unlike the debug image which did not run and gave an error as follows.

gdbserver: Error disabling address space randomization: Operation not permitted
/bin/sh: 1: exec: /Hello/Hello: not found
During startup program exited with code 127.
Exiting

Why does the release image run when invoked from a terminal like Putty but the debug one does not?

I was able to reproduce your error message by running docker run <debug-img> on the device, where <debug-img> is the name of the debug docker image.

The actual docker run command that VSCode uses when starting the debug container has more arguments needed to run properly. You can obtain it by pressing F1 in VSCode, then selecting ‘Torizon: export docker command line’.

Note that even when running the proper docker run command on the device the app will not start immediately if it is a debug build: your program will begin with gdbserver, and will be listening to a remote connection until a GDB/GDB-multiarch client connects to it.

While you can connect to it manually by creating a new terminal in VSCode and running all the necessary commands, we recommend debugging using VSCode directly, as instructed in the article I’ve linked in my previous answer: In debug configuration (switch to it using F1 → Torizon C/C++: Switch to debug configuration; if this option is not available you’re all set) just press F5 and VSCode will take care of the rest.

I hope I was able to clarify your question.

Best regards,
Lucas Akira