我设置了这样的环境变量:
XXX_ENV H:\xxx
我能看到
H:\xxx
当我运行命令时
echo %XXX_ENV%
在cmd中。 然后我有一个像这样的 Qt .pro 文件:
> INCLUDEPATH += ($$(XXX_ENV))/include
但不幸的是 INCLUDEPATH 不起作用,我无法使用 H:\xxx\include 中的那些 .h 文件
如何在 qmake 文件中使用环境变量?
----------------------更新---------------------- -----------
可能是我的描述不够详细。
情况确实如此。我在我的项目中引入了第三方组件。相关文件位于 H:\XXX 中,我可以使用 H:\XXX\include 中的头文件。所以我的qmake可以这样写:
INCLUDEPATH += H:/XXX/include
然后我可以使用 H:\XXX\include 目录下的头文件“aaa.h”,如下所示:
#include <aaa.h>
但我不想在qmake文件中写入绝对路径。所以我设置了一个Windows环境变量(不是qmake文件的变量)XXX_ENV,它的值是“H:\XXX”(或“H:/XXX”)。
我只是想知道我可以写 INCLUDEPATH += $${XXX_ENV}/include 而不是 INCLUDEPATH += H:/XXX/include
我尝试过,但没有成功。
最佳答案
请参阅documentation详情:
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)
您的问题似乎对于“不起作用”到底意味着什么不准确,但您应该使用 quote function路径中是否有空格等。
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.
关于qt - 如何在 Qt qmake 文件(Windows)中使用环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26621709/