Unsolved Set run environment from script in QtCreator
Is there a way to have a shell script automatically sourced to set the run environment in QtCreator (4.3.0, if that matters -- and on Linux obviously)?
My projects use CMake and at one step it generates a bash script with a lot of environment variables. This script is specific to each project, and its content may change depending on some of the options that are passed to CMake (such as which modules are to be included in the project and so on), so I cannot simply edit my user environment. The normal way to start the program (i.e. not through QtCreator) is to call another script that first source this one to set the variables and then launches the executable.
At the moment, whenever that file changes, I have to go to the run environment and use the "Batch Edit..." option, then copy-paste the content of the file in there. This is obviously not ideal, I sometime forget that the script has changed and get weird results in my application because of that... Plus, any copy-paste is a source of potential errors!
So, is there a way I could tell QtCreator to automatically source that script before running the application, instead of doing that manually?
I know that I can set a custom executable as the run target (i.e. the script that source the environment script + launches the true executable), but doing so means that e.g. starting the debugger directly doesn't work as it tries to debug the script and not the executable!
I've also found another question that seems exactly identical to what I want to do, but it is from 2015 and hasn't got a single answer, so hopefully someone will have an idea now?
@rmoyen , Did you ever find a solution to your problem? I having exactly the same issue on Ubuntu and would really like to know if there is a good answer for it.
I'm not aware that would be possible, beside the mentioned custom executable.
I have exactly the same problem here, but on macOS. We use conan to bundle our dependent libraries (VTK, opencv, ...) and obviously each libraries have an independent path which is, of course, not
/usr/lib. This require us to set
DYLD_FALLBACK_LIBRARY_PATHfor each library to allow the executable to run (using linker RPATH is not an option since conan libraries can be installed virtually anywhere). Our cmake generate the correct script that set the variable for us, but we fall in the described problem here, as, even if setting a custom executable allow us to launch the application, we cannot debug it since the debugger seems to attach to the shell that execute the script rather than the launched application. Setting
DYLD_FALLBACK_LIBRARY_PATHas an environment modifier inside the run environment is not doable because the run environment is the same for debug and release build (and the dependent libraries are not, so different paths !). Furthermore, it is just really painful to set it for all dependent libraries...
So if someone have a solution to attach the debugger to a custom executable that is a script, or to use an external script to generate the run environment, we will be glad ;)