Creation of C++ CMake Applications fail from VSCode

Hello

I’m currently facing the issue that I can not deploy and debug C++ applications from VSCode. The VSCode Plug-In is up to date and the Verdin SoM was installed with the current Easy Pairing image.

What's Next?
  View a summary of image vulnerabilities and recommendations → docker scout quickview
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: DOCKER_HOST= docker run --rm -v /home/karsten-lnx/Desktop/TestProject:/home/torizon/app cross-toolchain-arm64-test-project cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -Bbuild-arm64 

CMake Error: Unable to (re)create the private pkgRedirects directory:
/home/torizon/app/build-arm64/CMakeFiles/pkgRedirects

 *  The terminal process "/usr/bin/bash '-c', 'DOCKER_HOST= docker run --rm -v /home/karsten-lnx/Desktop/TestProject:/home/torizon/app cross-toolchain-arm64-test-project cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -Bbuild-arm64'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello,

The error you’re encountering, “CMake Error: Unable to (re)create the private pkgRedirects directory,” suggests there might be an issue with directory permissions or Docker volume mounting. Here are some steps to troubleshoot and resolve this issue:

  1. Check Directory Permissions:

    • Ensure that the directory /home/karsten-lnx/Desktop/TestProject and its subdirectories have the correct permissions set, allowing the user to write to them. You can use the command chmod -R 755 /home/karsten-lnx/Desktop/TestProject to set appropriate permissions.
  2. Verify Docker Volume Mounting:

    • Confirm that the Docker volume is correctly mounted. The command you provided mounts the project directory to /home/torizon/app inside the container. Ensure that this path is correct and accessible.
  3. Container Permissions:

    • Make sure the Docker container has the necessary permissions to write to the mounted volume. You might need to adjust the user permissions within the container or run the container with elevated privileges.
  4. Configuration Files:

    • Check your .vscode/tasks.json and other configuration files for any misconfigurations related to paths or permissions. Ensure that the paths specified in these files match the actual directory structure.
  5. Rebuild the SDK Container:

    • If the issue persists, try rebuilding the SDK container. This can be done by running the command Remote-Containers: Rebuild Container from the command palette in Visual Studio Code.

These steps should help you resolve the issue with deploying and debugging your C++ application using the Torizon extension in Visual Studio Code.

Best regards, Toradex AI Assistant.

Please, also check if these links can help you solve your problem:

How to cross compile rtl8192eu driver for imx8mp?.

Hi,

just for verification.
I am facing the error while using the stock Torizon Image with Easy Pairing containers together with the unmodified C++ Project created by the Torizon PlugIn in VSCode.

Greetings @KDehren,

This sounds like a permissions issue. As seen in your logs a container bind-mounts the directory /home/karsten-lnx/Desktop/TestProject from your host machine. The container will then run cmake to configure the build, which will result in files and directories being created in /home/karsten-lnx/Desktop/TestProject.

Now for whatever permission related reason, the container can’t create files/directories in /home/karsten-lnx/Desktop/TestProject. I’m not exactly sure why on your PC you have this permission issue, to clarify I don’t get this issue on my setup. I’m not sure if you’re on Linux or WSL or how you have your PC setup/configured. Generally I would say to change the permissions on your directory so that the container can write to it.

This other thread a customer got a similar error and found a way to workaround the permission issues: Qt Template Project not working on Ubuntu Linux

Best Regards,
Jeremias

1 Like

I was testing the VSCode extension and got the same problem. I believe I found the origin.
The Docker containers that are run by VSCode tasks use, inside the container, a user called torizon. This user most likely is UID 1000, GID 1000, like the standard first user created. If the files owner is a different user, in my case UID 1001, GID 1001, and if they have the standard permissions, the user 1000:1000 cannot modify it.

You can make the Docker run the container with a different user by adding the following flag: -u : with the uid and gid of the user you want. The containers that are automatically run by VSCode to build and compile the code are configured as tasks. You can edit their arguments and flags in the file /.vscode/tasks.json. For exemple, here is my task “build-configure-arm64“:

{

        "label": "build-configure-arm64",

“hide”: true,

“command”: “DOCKER_HOST=”,

“type”: “shell”,

“args”: [

“docker”,

“run”,

“–rm”,

“-u”,

“1001:1001”,

“-v”,

“${workspaceFolder}:${config:torizon_app_root}”,

“cross-toolchain-arm64-cmake_1”,

“cmake”,

“-DCMAKE_BUILD_TYPE=Debug”,

“-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++”,

“-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc”,

“-Bbuild-arm64”

        \],

“problemMatcher”: [

“$gcc”

        \],

“dependsOrder”: “sequence”,

“dependsOn”: [

“build-container-image-sdk-arm64”

        \],

“icon”: {

“id”: “tools”,

“color”: “terminal.ansiYellow”

        },

“presentation”: {

“echo”: true,

“reveal”: “always”,

“focus”: true,

“panel”: “shared”,

“group”: “build-execution”

        }

    },

Note the “-u”, “1001:1001”, .The problem is that you would have to add these lines in every task that creates a container that access the file. Not very nice.I’ll probably try to use Access Control Lists to add permissions to the user 1000 specifically, but I still need to look up how this works.

Also, I checked the container image to try to find where the user was created. It’s in the cross-toolchain-arm64 base image, so this problem will most likely be present with every base Toradex container.

Adding a bit on top of Vicente’s fix here. In regards to why this happens: Torizon’s Debian-based containers fix the torizon user at UID/GID 1000:1000, and on native Linux Docker, bind mounts keep the hosts ownership. Which means that if your Linux user isn’t UID 1000, the container can’t write into the mounted project folder.

Two notes on the -u fix: double check it’s --rm (double hyphen), not –rm, and you’ll need to add -u <your uid>:<your gid> to every task that mounts the workspace, not just one.

An alternative that avoids editing tasks.json at all: fix it once with ACLs so the container keeps running as its normal torizon user:

  sudo apt install acl   # if setfacl isn't already there
  setfacl -R -m u:1000:rwX /path/to/your/project
  setfacl -R -d -m u:1000:rwX /path/to/your/project

Also, something to keep in mid is that torizon_run_as in .vscode/settings.json only affects the debug container, not the plain docker run tasks. So it wouldn’t have fixed this particular error.