il_mix
il_mix

Reputation: 571

Linux environment variable not recognized by qmake in QtCreator

I'm facing a problem with a project where I need to retrieve an environment variable to link some external libraries, that works correctly on Windows. In Linux it looks like qmake (run from QtCreator) isn't able to "decode" an environment variable I've set in my .bashrc, declared like this

export ProjectsDir=/home/il_mix/Projects/

To better define the problem, I've made a veeery minimalistic .pro file, that contains just this

message($$(ProjectsDir))

If I run qmake from the terminal with the command

/opt/Qt/5.9.1/gcc_64/bin/qmake test.pro

I get the correct output

Project MESSAGE: /home/il_mix/Projects/

When I open the .pro from QtCreator, I get an empty Project MESSAGE instead.

From QtCreator options I see that my one and only kit has "qmake location" set to /opt/Qt/5.9.1/gcc_64/bin/qmake, so the same I've used from terminal.

I've noticed that on the Projects settings, under Build/Run Environment, one can see the available variables. "ProjectsDir" is not listed in any available environment (Build, System). On Windows my environment variable is instead listed, and so recognized by qmake.

Is there any other setting I'm missing to let environment variables work under QtCreator?

Here is the output from qmake -v

QMake version 3.1
Using Qt version 5.9.1 in /opt/Qt/5.9.1/gcc_64/lib

Upvotes: 1

Views: 2805

Answers (1)

il_mix
il_mix

Reputation: 571

I solved my problem.

QtCreator looks for system-wide environment variables, while the ones set in .bashrc or .bash_profile are valid only for the user.

To set a system-wide environment variable one can add it to /etc/environment. Following my example, I have to append this line to the file

ProjectsDir=/home/il_mix/Projects

Then QtCreator recognize the variable.

To be more multi-user friendly one can set the variable in '/etc/profile` instead. This way the environment variable can contain another environment variable, like

export ProjectsDir=$HOME/Projects

I suppose the different behavior is due to the fact that the files (/etc/environment and /etc/profile) are sourced in a different time.

Upvotes: 3

Related Questions