Cross compiling C++ Apps

Hello! I have C ++ applications using OpenCV and CUDA, how can I cross-compile? I tried it according to the instructions (https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/flashing.html#wwpID0E06I0HA), but nothing worked. The program also continues to compile on my host computer.

For example i tried compile cuda-samples (GitHub - NVIDIA/cuda-samples: Samples for CUDA Developers which demonstrates features in CUDA Toolkit)

I use JetPack 4.4.1

Thanks!

You might want to post the actual compile error, including a bit of what shows up in build messages prior to the error. In general though, this is often due to an insufficient “sysroot”. The sysroot is basically all of the files used during a build or link from user space. Examples being header files and libraries. Most sysroots you might find available are quite minimal, and require you to use that to build libraries and other content manually.

If you were to add everything you needed to a Jetson to build natively, and then clone the Jetson, you could use that clone mounted on loopback as the sysroot. This won’t guarantee success, but it is by far the most complete sysroot you’d ever get. The cloned sysroot could also be later updated via rsync if desired, or even used as a backup so the Xavier could be restored if something went wrong.

1 Like

Hello! Thanks for you answer.

I’m afraid I didn’t explain correctly. I don’t get any error.

I did the following steps:

  1. Made a copy of Jetson
  2. Mounted backup.img.raw on my host
  3. export TARGET_ROOTFS = $HOME/jetson
  4. download the pre-build toolchain
  5. export PATH = <CROSS_COMPILER_PATH> / bin: $ PATH
    export CROSS_COMPILE = aarch64-linux-gnu-
  6. Downloaded cuda-samples and tried to compile deviceQuery example. the compilation was successful, but the program was compiled for my host computer, and not arm as it should have.

Where did i go wrong?

Is your final “CROSS_COMPILE” a full path to:
/usr/bin/aarch64-linux-gnu-

If it is just a part of a default path, then I could see the possibility that it is not finding the correct compiler. An export which is just “aarch64-linux-gnu-”, without the absolute path prefix, might not be doing what you think it is doing.

Thanks.

In order to better understand this problem, what is required of me? What information should I give you so that you can help?

What is the full path to your “aarch64-linux-gnu-gcc” app? Is it here?
/usr/bin/aarch64-linux-gnu-gcc
(g++ would also be there)

  • What is your full exact compile command line?
  • Include any export of environment variables.
  • Include where you have any loopback mounted image for sysroot.
  • Include if the actual Xavier the clone is from an Xavier which can natively compile the same software. This of course depends on whether you have a clone. If not a clone, then suggest where your sysroot is from.
  • Prior to compile, what do you see from “echo $PATH”? This should be from after you’ve performed any kind of export so changes from the export can be seen.

Note that much of that won’t matter since you followed the documentation, but it seems something simple is at issue, and really the whole chain of build instructions needs to be verified.

Now i found and downloaded “gcc-linaro”, respectively i do next command:

  • export CROSS_COMPILE=/home/user/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
  • I have my Jetson clone (backup.img.raw) and i mount them.
  • export TARGET_ROOTFS = $HOME/jetson
  • my echo $PATH → /home/user/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-

Now i have compile error about ‘/usr/bin’ not included in the PATH environment variable :D

For the below I will make the assumption that you loopback mounted the backup.img.raw clone to “$HOME/jetson” (a.k.a., “~/jetson”).

The error message is not sufficient by itself to know for sure, but it is possible that you need to name extra paths for binaries which are arm64/aarch64. When naming “/usr/bin” one is referring to the host PC’s binaries, and an error about missing this may instead be related to the cross architecture content of “~/jetson/usr/bin”. Don’t know for sure. Can you post the directory the compile is run from, along with the full compile log? Or at least the last page of build logs before and through the full compile error? I’m looking for some context about what was going on prior to the failure, along with exact failure messages.

NOTE: If you set your $PATH to only the cross compile path, then you would have erased your other $PATH content. If you separate the existing $PATH with a colon (“:”) and then append the new content (or reverse, start with new content, add “:”, then append old PATH content), this should work better. For example:
export PATH="/home/user/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-:${PATH}"

Note that PATH is a colon-delimited set of paths, not a single path.