我如何在Qt qmake文件(Windows)中使用环境变量?(How can I use environment variable in a Qt qmake file (Windows)?)

编程入门 行业动态 更新时间:2024-10-25 17:27:49
我如何在Qt qmake文件(Windows)中使用环境变量?(How can I use environment variable in a Qt qmake file (Windows)?)

我已经设置了一个像这样的环境变量:

XXX_ENV H:\ xxx

我可以看到

H:\ XXX

当我运行命令

回声%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 \目录下的头文件“aaa.h”,就像这样:

#include <aaa.h>

但我不想在qmake文件中写绝对路径。 所以我设置了一个Windows环境变量( 不是qmake文件的变量 )XXX_ENV,它的值是“H:\ XXX”(或“H:/ XXX”)。

我只想知道我可以写INCLUDEPATH + = $$ {XXX_ENV} / include而不是INCLUDEPATH + = H:/ XXX / include

我试过了,但没有奏效。

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.

最满意答案

有关详细信息,请参阅文档

变量可以用来存储环境变量的内容。 这些可以在qmake运行时进行评估,或者在项目生成时包含在生成的Makefile中进行评估。

要在运行qmake时获取环境值的内容,请使用$$(...)运算符:

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

你的问题似乎不确定“究竟什么不行”意味着什么,但如果你在路径中有空格,你应该使用引用函数等。

引号(字符串)

将整个字符串转换为单个实体并返回结果。 这只是将字符串括在双引号中的一种奇特方式。

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.

更多推荐

本文发布于:2023-08-04 12:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415926.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境变量   文件   如何在   qmake   Qt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!