简体   繁体   中英

How can I use environment variable in a Qt qmake file (Windows)?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM