6

I have setted an environment variable like this:

XXX_ENV H:\xxx

I can see

H:\xxx

when I run command

echo %XXX_ENV%

in cmd. Then I have a Qt .pro file like this:

> INCLUDEPATH += ($$(XXX_ENV))/include 

but unfortunately the INCLUDEPATH don't work, I can't use those .h file in H:\xxx\include

How can I use the environment varibale in qmake file ?

---------------------update---------------------------------

May be my description is not detaild enough.

This is the case. I have introduced a third party component into my project. The relevant files are in H:\XXX and i can use head files in H:\XXX\include. So my qmake can be writed like this:

INCLUDEPATH += H:/XXX/include 

Then I can use head file "aaa.h" which is under directory H:\XXX\include just like this:

#include <aaa.h> 

But I don't want to write the absolute path in the qmake file. So I seted a Windows environment variable(not qmake file's variable) XXX_ENV and it's value is "H:\XXX"(or "H:/XXX").

I just want to know can I write INCLUDEPATH += $${XXX_ENV}/include instead of INCLUDEPATH += H:/XXX/include

I tried it but it didn't work.

2
  • @lpapp Thank you for your answer, I think the problem has been resolved. Commented Nov 4, 2014 at 4:59
  • For using the system environment variable in qmake, just write it as $$(XXX_ENV) but not $${XXX_ENV}. Commented Nov 4, 2014 at 5:01

1 Answer 1

16

See the documentation for details:

Variables can be used to store the contents of environment variables. These can be evaluated at the time that qmake is run, or included in the generated Makefile for evaluation when the project is built.

To obtain the contents of an environment value when qmake is run, use the $$(...) operator:

 DESTDIR = $$(PWD) message(The project will be installed in $$DESTDIR) 

Your question seems to be imprecise as to what exactly "does not work" means, but you ought to use the quote function should you have spaces in the path, etc.

quote(string)

Converts a whole string into a single entity and returns the result. This is just a fancy way of enclosing the string into double quotes.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.