Qt Creator中OpenCV程序中的链接器错误
Linker error in OpenCV Program in Qt-Creator
我在安装OpenCV-3的Qt Creator Qt-5.4中收到以下错误:-
:-1:错误:LNK1104:无法打开文件'opencv_ts300.lib'
在我项目的.pro文件中,我添加了-
INCLUDEPATH += "E:opencvbuildinclude"
LIBS += -L"E:opencvbuildx86vc11lib"
LIBS += -lopencv_ts300d -lopencv_world300d -lopencv_ts300 -lopencv_world300d
以下是我的主要.cpp程序:-
#include "mainwindow.h"
#include <QApplication>
#include<opencv2/opencv.hpp>
using namespace cv; // else would have to specify cv::cvtColor() etc.
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
char * imageName ="2-dp.JPG" ; // read the name of image to be loaded called 3-dp.JPG
Mat image; // declare Mat type object to load image-matrix
image = imread(imageName,1); // image object now contains image-matrix of the image loaded
if(!image.data) // if image-data was invalid/non-existent/could not be read
{
printf("No image data to load n"); // then print messg
return -1; // and exit program with exit code -1
}
Mat gray_image; // Mat object declared for the image after gray-scale conversion
cvtColor(image, gray_image, CV_BGR2GRAY); // converts from BGR/RGB color space to gray scale
/*imwrite ("Gray_Image.jpg",gray_image);*/ //writes image-data (converted to gray scale iamge) into disk in JPEG format at file path given
namedWindow(imageName,CV_WINDOW_AUTOSIZE); // creates a named window for original image s.t window auto-scales its size as per image
namedWindow("Gray Image",CV_WINDOW_AUTOSIZE);
imshow(imageName,image); // displays the image on the namedWindow by giving name of namedWindow
imshow("Gray Image",gray_image);
waitKey(0); //waits forever till user presses key
return a.exec();
}
请帮忙!
链接
不应在一行中的库名称之间使用反斜杠符号。它不会给出问题中提到的错误消息,但是链接失败,并返回相同的错误代码。
反斜线符号可用于打断长行:
LIBS += -lopencv_ts300d
-lopencv_world300d
否则,库应在没有:的情况下列在一行中
LIBS += -lopencv_ts300 -lopencv_world300
运行时
运行时可能会发现一些问题。
有两种库类型:debug(用后缀d
标记)和release。它们不应该混合在一个构建中。使用错误的库类型可能会导致运行时崩溃,例如,当使用HoughLinesP 时,Qt中的OpenCV在行的向量的释放时崩溃
根据发布或调试模式,可以编写仅使用适当库的qmake
.pro
文件:
INCLUDEPATH += "E:opencvbuildinclude"
LIBS += -L"E:opencvbuildx86vc11lib"
CONFIG(release, debug|release) {
# release libraries
LIBS += -lopencv_ts300 -lopencv_world300
}
CONFIG(debug, debug|release) {
# debug libraries
LIBS += -lopencv_ts300d
-lopencv_world300d
}
请注意,E:opencvbuildx86vc11bin
中还有二进制动态加载库。如果在运行时找不到这些库,则应用程序应该崩溃。该路径可以被添加到系统PATH
环境变量,或者所需的库可以被复制到应用程序文件夹或系统PATH
中列出的其他位置。
确保您使用的是vc11
的编译器、链接器和Qt构建。对于MSVC2013,应使用文件夹vc12
(E:opencvbuildx86vc12lib
)中的库。
相关文章:
- 静态数据成员的问题-修复链接错误会导致编译器错误
- Visual Studio mkl_link_tool.exe链接错误
- C++ 实现模板单例类时出现链接错误
- 使用类模板的方法链接错误
- MySQL C++连接器链接错误
- VS 2015 链接错误 无法构建依赖于 libcurl 的项目
- 运行 C++ 单元测试时LNK2005链接错误
- 对 CMake 中'cudaRegisterLinkedBinary'链接错误的未定义引用?
- 链接错误,包括我创建的相同头文件 - C++
- 在Embarcadero C++ Builder中生成的DLL未解决的外部链接错误
- 使用标头保护的多个定义链接错误
- 链接错误:未定义对 stdscr 和 wgetch 的引用
- 使用 Vivek 的 Vcam / 捕获源过滤器构建/链接错误
- 升压program_options中的链接错误
- 使用 g++ 预处理器进行替换会导致链接错误
- 在调试配置中编译工作正常,但发布会给出链接错误
- 相邻矩阵设置链接错误
- 包含常量变量并包含在多个文件中的标头的链接错误
- C++链接错误,我理解但无法解决
- 是什么导致macOS Mojave上的GoogleTest链接错误