skip to Main Content

I want to cross compile a project on a remote Linux PC for an embedded target, but it requires environment setup.

I have an environment setup script. I can run this script on the remote Linux PC in the shell and it correctly sets my environments variables. The build script uses these environment variables and it successfully builds locally.

I connect to the PC with VsCode using the remote SSH Extension. I cannot seem to build in the external VsCode. The environment variables are not set even though I setup the environment via a task. The build script cannot find the right paths because of this.
Here is my tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "env",
            "type": "shell",
            "command": "source", 
            "args": ["/opt/fslc-framebuffer/2.5-qt/environment-setup-armv7at2hf-neon-fslc-linux-gnueabi"]
        },
        {
            "label": "qmake frontend",
            "type": "shell",
            "command": "/opt/fslc-framebuffer/2.5-qt/sysroots/x86_64-fslcsdk-linux/usr/bin/qmake",
            "args": ["${workspaceFolder}/frontend/frontend.pro", "-config", "release", "CONFIG+=imx6ul-linux"],
            "problemMatcher": [
                "$gcc"
            ],
        },
        {
            "label": "build frontend",
            "dependsOn": [
                "env",
                "qmake frontend"
            ],
            "dependsOrder": "sequence",
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
  }
  

I also tried the following, but it didn’t help:

2

Answers


  1. It seems like the issue is with the environment setup not persisting across tasks in VsCode. As far as I know, each task in VsCode runs in its own isolated environment, so environment variables set in one task are not carried over to other subsequent tasks.

    You can try running a bash shell and within that shell you can execute the environment setup script using source.Then, you run the qmake command and make commands sequentially.

    By doing this, the environment variables set in the environment setup script should be available for the entire build process.

    Login or Signup to reply.
  2. The sharing of the environment depends on how VS Code handles the console, i.e., whether it reuses it or not.

    You can create a bash script with all these commands, which is one way to avoid depending on VS Code’s undocumented behaviors.

    Create run_build.sh and put it under ${workspaceFolder}.

    source /opt/fslc-framebuffer/2.5-qt/environment-setup-armv7at2hf-neon-fslc-linux-gnueabi
    /opt/fslc-framebuffer/2.5-qt/sysroots/x86_64-fslcsdk-linux/usr/bin/qmake ./frontend/frontend.pro -config release CONFIG+=imx6ul-linux
    

    tasks.json could be:

            {
                "label": "build frontend",
                "type": "shell",
                "command": "run_build.sh", 
                "problemMatcher": [
                    "$gcc"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                }
            }
    

    If you don’t want to create a new script, just combine them in tasks.json.

    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "test",
          "type": "shell",
          "command": "source <env config>; qmake <args go here>"
        }
      ]
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search