[英]The path to include header files
Assuming there is C:\somelib\headerfromsomelib.h
.假设有
C:\somelib\headerfromsomelib.h
。 I used to put on my project.pro
the following我以前在我的
project.pro
上放了以下
INCLUDEPATH += C:\somelib
And on file.cpp
I will put在
file.cpp
我会放
#include "headerfromsomelib.h"
Then hitting F2
over it will led me to that header file.然后
F2
将我带到 header 文件。
In another approach I can, instead, add C:\somelib
to the INCLUDE
environment variable.在另一种方法中,我可以将
C:\somelib
添加到INCLUDE
环境变量中。 So its not necessary to add anything to the pro file.所以没有必要在 pro 文件中添加任何东西。 And it still builds.
它仍然在构建。 I found this approach interesting since it adds flexibility, in a project with multiple developers everyone will be able to have
somelib
in a different path.我发现这种方法很有趣,因为它增加了灵活性,在一个有多个开发人员的项目中,每个人都可以在不同的路径中使用
somelib
。
However hitting F2
on the include line on QtCreator will not led me to the header file anymore.但是,在 QtCreator 的包含行上
F2
不会再将我带到 header 文件。 Am I missing something or this is a downside of the this approach?我是否遗漏了什么或者这是这种方法的缺点?
A more reliable way of using environment variables for library paths is to create environment variables for each library.将环境变量用于库路径的一种更可靠的方法是为每个库创建环境变量。 Eg create an environment variable
SOMELIB_PATH
then you can do:例如创建一个环境变量
SOMELIB_PATH
然后你可以这样做:
INCLUDEPATH += $$(SOMELIB_PATH)
This can be extended for libraries you need to link to as well:这也可以扩展到您需要链接到的库:
INCLUDEPATH += $$(SOMELIB_PATH)/include
LIBS += -L$$(SOMELIB_PATH)/lib -lsomelib
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.