0

My launch.jason

"environment": [{
    "name": "LD_LIBRARY_PATH",
    "value": "/opt/OpenBLAS/lib:/home/peter/anaconda3/lib"
}]

My task.jason

"task": {
    // set LD_PATH environment
    "type": "node-terminal",
    "label": "setenv",
    "command": "export",
    "args": ["LD_LIBRARY_PATH=/opt/OpenBLAS/lib:/home/peter/anaconda3/lib"]
   }

Everything builds properly, all -I,-L,-l are in the task.jason (not shown for clarity).

If I run : export LD_LIBRARY_PATH=/opt/OpenBLAS/lib:/home/peter/anaconda3/lib at the terminal, then run the program, it runs perfectly. It will continue to run once I've exported the env variable at the terminal. If I quit VSCode and then reenter and run the program, it can't find the link libs at run time, but, again, if I run export at the terminal, it runs perfectly. Obviously, the shell the program is running in does not inherit the env variables. Before I export if I run echo $LD_LIBRARY_PATH, they are correct, but the program can't find them at link time if I don't export them.

I have not found any doc or stackoverflow that fixes this problem. Inheriting the run env is pretty basic. In Eclipse there's a check box to inherit the env (or not) at runtime and the same program with the same build libs and includes run perfectly. Any "simple" fix for this?

starball
  • 20,030
  • 7
  • 43
  • 238
  • I think you are misunderstanding the purpose of VS Code's launch.json/tasks.json. You are supposed to run your program _as part of launch.json_. The tasks.json is for compiling or building an executable of your program, passing in compile-time/build-time args like LD_LIBRARY_PATH. Then launch.json is for running your program, usually by first calling a compile/build task in tasks.json, then running the resulting executable. If you need to set some run-time env vars, you do it as well from launch.json, and the launched program will inherit the same env where those env vars are set. – Gino Mempin Aug 11 '23 at 00:38
  • see the tasks and terminal sections of my post here: https://stackoverflow.com/a/76880129/11107541. I propose that this question be closed as a duplicate to the question where I posted that answer. If people disagree, let me know and I can write up a more customized answer here. – starball Aug 11 '23 at 01:12

0 Answers0