C++ 包括在 Qt Creator 中添加外部库的路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20588440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:13:32  来源:igfitidea点击:

Include path for adding an external library in Qt Creator?

c++qtopencvqt-creator

提问by user3103152

I am trying to include the pre-compiled (MSVC2012) OpenCV static libraries into Qt Creator but I am unsure what the include path is about as per this image: http://i.stack.imgur.com/Pmsqq.png

我正在尝试将预编译的 (MSVC2012) OpenCV 静态库包含到 Qt Creator 中,但我不确定根据此图像包含的路径是什么: http://i.stack.imgur.com/Pmsqq.png

Here is an image of the precompiled OpenCV files that I downloaded: http://i.stack.imgur.com/vNRNt.png

这是我下载的预编译 OpenCV 文件的图像: http://i.stack.imgur.com/vNRNt.png

There are 3 directories: bin contains DLLs, lib contains small lib files (2 kb) so that QtCreator can understand the DLLs, and staticlib containts large lib files (1 mb) which are the static libraries that I'm trying to link against.

有 3 个目录:bin 包含 DLL,lib 包含小库文件 (2 kb),以便 QtCreator 可以理解 DLL,以及 staticlib 包含大库文件 (1 mb),它们是我试图链接的静态库。

The library file/path is something like C:\opencv\build\x86\vc11\staticlib\opencv_features2d247d.lib, right? There are roughly 50 lib files. Do I have to each one manually?

库文件/路径类似于C:\opencv\build\x86\vc11\staticlib\opencv_features2d247d.lib,对吗?大约有 50 个 lib 文件。我必须手动每一个吗?

回答by Zlatomir

See the documentation for include path, and libs.

请参阅include pathlibs的文档。

Also note that you need to link with the files ending with 'd' in the debug build and the others in release (also if you use x86 and x64 builds, you should use the correct libraries), here is a sample from a test .pro (i only use x86 and vc10):

另请注意,您需要链接调试版本中以 'd' 结尾的文件以及发布中的其他文件(如果您使用 x86 和 x64 版本,则应使用正确的库),这是来自 test 的示例。专业版(我只使用 x86 和 vc10):

INCLUDEPATH += D:\ProgrammingTools\opencv\build\include

CONFIG( debug, debug|release ) {
LIBS += -LD:\ProgrammingTools\opencv\build\x86\vc10\lib\
    -lopencv_core246d\
    -lopencv_highgui246d\
    -lopencv_imgproc246d\
    -lopencv_features2d246d\
}
else {
LIBS += -LD:\ProgrammingTools\opencv\build\x86\vc10\lib\
    -lopencv_core246\
    -lopencv_highgui246\
    -lopencv_imgproc246\
    -lopencv_features2d246\
}

Notice that there is -L__NO_SPACE_PATHTOLIB and -l_NOSPACE__libname, you don't need to add all the lib files, you only add the ones that you use functions from, and also the samples include files like this:

请注意,有 -L__NO_SPACE_ PATHTOLIB 和 -l_NOSPACE__libname,您不需要添加所有的 lib 文件,您只需添加您使用的函数的那些,并且示例包括这样的文件:

#include <opencv2/opencv.hpp>

so the include-path ends in a folder that contains two folders (not the actual header files)

所以包含路径以包含两个文件夹的文件夹结尾(不是实际的头文件)