Simple cross compile C application

Dear all,

Nvidia provides a lot of technical information. However i didn’t find a simple tutorial which explains how to cross-compile a simple C ‘hello world’ application.

Please advise

Thanks.

Nissim.

Did you compile the c file on Xavier? Stand gcc should be working for it.

Dear all,

I would like to compile the application on my host PC, using a cross-compile tool-chain.

Have a reference to below link

In case it helps you might be interested in the following (random) information…

When you build a kernel or bootloader by cross compile, the code is entirely static. There is no link to any outside library. This is bare metal, and is the simplest cross compile.

User space programs need libraries to link against. To that extent you would also need a cross linker and a “sysroot”, where the sysroot is basically a minimal set of libraries from the foreign architecture, and the cross link runs on the naive architecture, but only linking the foreign architecture. It is the user space part which really complicates life.

Some “sysroot” content is available on the web in various forms. The same for cross linking tools (which is basically why they call it a toolchain instead of just a tool). The plain vanilla sysroots have what you need to build other libraries, and the most basic of software. On the other hand, if your software requires other libraries, e.g., GTK, CUDA, some OpenGLES files, so on, then it gets complicated fast trying to build all of those yourself.

You could copy files from the Jetson one at a time, and then you’d know you are using the correct file since linking will be performed against what the Jetson actually has on it. Or, you could clone, mount the clone on loopback on the host PC, and use the subdirectories directly from the clone for your sysroot.

Every library has a chance that it links to yet another library. If you find you need to copy a GTK library for example, then it might fail because you lack the libraries for handling character sets. Then you might add the library for handling character sets, and might find it fails because this library needs other library, and so on. The clone, if you added the development packages to the Jetson prior to cloning, is guaranteed to have everything you need, and to have it in the right release.

You might be interested in:
https://devtalk.nvidia.com/default/topic/1048996/jetson-agx-xavier/cross-compile-for-jetson-xavier-/post/5323843/#5323843
https://devtalk.nvidia.com/default/topic/1043115/jetson-tx2/cross-compiler-version-problem/post/5292337/#5292337

A typical clone requires a lot of extra disk space, e.g., 35GB minimum and you are close to filling up your PC. However, the gist is that if the Xavier is in recovery mode with the USB-C connected to host, then in your “Linux_for_Tegra/” directory from any previous flash, it goes like this:

sudo ./flash.sh -r -k APP -G my_backup.img jetson-xavier mmcblk0p1

This would produce two files, the “sparse” my_backup.img, and the “raw” my_backup.img.raw. You would want to throw away the sparse image, and keep the raw image. This image takes a long time to copy to another disk since it is enormous, but this is the one you can loopback mount.