[英]Qt #include not working with External Library
I am fairly new to Qt 5 and Qt Creator . 我对Qt 5和Qt Creator还是陌生的。 I created a library project called D20Controls. 我创建了一个名为D20Controls的库项目。 I have the D20Controls.lib file. 我有D20Controls.lib文件。 In my project, I want to use classes of my lib D20Controls. 在我的项目中,我想使用lib D20Controls的类。 So I right-click on my project and do Add Library... I choose External library and I browse up to my D20Controls.Lib file. 因此,我右键单击我的项目,然后执行“添加库...”。选择“外部库”,然后浏览至D20Controls.Lib文件。 Now everything seems to be added correctly to my .pro file. 现在,所有内容似乎都已正确添加到我的.pro文件中。
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../build-D20Controls-Desktop_Qt_5_1_1_MSVC2012_64bit-Debug/release/ -lD20Controls
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-D20Controls-Desktop_Qt_5_1_1_MSVC2012_64bit-Debug/debug/ -lD20Controls
INCLUDEPATH += $$PWD/../../build-D20Controls-Desktop_Qt_5_1_1_MSVC2012_64bit-Debug/debug
DEPENDPATH += $$PWD/../../build-D20Controls-Desktop_Qt_5_1_1_MSVC2012_64bit-Debug/debug
win32:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../../build-D20Controls-Desktop_Qt_5_1_1_MSVC2012_64bit-Debug/release/D20Controls.lib
else:win32:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../../build-D20Controls-Desktop_Qt_5_1_1_MSVC2012_64bit-Debug/debug/D20Controls.lib
but when I want to use it in my project #include <D20Controls>
or any .h file in it, I can't compile error like : ...main.cpp:4: error: C1083: Cannot open include file: 'D20Controls': No such file or directory 但是当我想在我的项目#include <D20Controls>
或其中的任何.h文件中使用它时,我无法编译如下错误:... main.cpp:4:错误:C1083:无法打开包含文件:' D20Controls:没有此类文件或目录
How can I do use my lib ? 我该如何使用我的库? (I have tried static linking and dynamic linking) (我尝试过静态链接和动态链接)
What am I missing ? 我想念什么?
Steps to solve a problem like this: 解决此类问题的步骤:
Find D20Controls.h
in your file system. 在文件系统中找到D20Controls.h
。 If there are several, decide which is the correct one you want to include. 如果有多个,请确定要包括的是正确的一个。
Find one actually executed compile command (for example one which has -o main.o
and main.cpp
in it), there are several but they should normally have same -I
flags within one project. 找到一个实际执行的编译命令(例如,其中包含-o main.o
和main.cpp
命令),有几个,但是通常在一个项目中它们应该具有相同的-I
标志。 If you compile from Qt Creator, look in the "Compile Output" tab at the bottom of the screen. 如果从Qt Creator进行编译,请查看屏幕底部的“编译输出”标签。 If you compile from command line, scroll up or even copy-paste to some editor. 如果从命令行编译,请向上滚动甚至复制粘贴到某个编辑器。
See if there is -I...something...
option on the compile command, which matches the location of correct include file. 查看compile命令上是否有-I...something...
选项,该选项与正确的include文件的位置匹配。
If not, add or fix it in the .pro
file, re-run qmake, build. 如果没有,请在.pro
文件中添加或修复它,然后重新运行qmake,进行构建。
Above applies for finding headers, and -I
flag for compile command, which specifies include path. 以上适用于查找头文件,以及-I
标志用于编译命令,该命令指定包含路径。 If it is linker that complains (which usually happens in case like this, after you fix includes), then find the link command (one with bunch of .o
files, and something like -o final-program-name
), and look for -L
option, which specifies link paths. 如果是链接器发出错误消息(通常在这种情况下发生,则在修复包含问题后会发生这种情况),然后找到链接命令(一个带有一堆.o
文件,以及-o final-program-name
),然后寻找-L
选项,它指定链接路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.