Qt (OSX) and OpenCV errors
Qt (OSX) and OpenCV errors
我一直在努力让OpenCV与Qt一起工作,但由于某种原因,它无法识别OpenCV库。我已经尝试了几乎所有关于堆栈溢出的教程,但由于某种原因它不起作用。
我收到的错误消息是。
10:50:36: Running steps for project test...
10:50:36: Configuration unchanged, skipping qmake step.
10:50:36: Starting: "/usr/bin/make"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -mmacosx-version-min=10.7 -Wl,-rpath,/Users/me/Qt/5.4/clang_64/lib -o test.app/Contents/MacOS/test main.o mainwindow.o moc_mainwindow.o -F/Users/me/Qt/5.4/clang_64/lib -L/usr/local/lib -framework QtWidgets -framework QtGui -framework QtCore -framework DiskArbitration -framework IOKit -framework OpenGL -framework AGL
Undefined symbols for architecture x86_64:
"cv::_InputArray::_InputArray(cv::Mat const&)", referenced from:
MainWindow::MainWindow(QWidget*) in mainwindow.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in mainwindow.o
"cv::imread(std::string const&, int)", referenced from:
MainWindow::MainWindow(QWidget*) in mainwindow.o
"cv::imshow(std::string const&, cv::_InputArray const&)", referenced from:
MainWindow::MainWindow(QWidget*) in mainwindow.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in mainwindow.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test.app/Contents/MacOS/test] Error 1
10:50:37: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project test (kit: Desktop Qt 5.4.0 clang 64bit)
When executing step "Make"
10:50:37: Elapsed time: 00:00.
这是我的 .pro 文件
#-------------------------------------------------
#
# Project created by QtCreator 2015-01-23T19:58:31
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test
TEMPLATE = app
INCLUDEPATH += /usr/local/include
HEADERS += mainwindow.h
LIBS += -L/usr/local/lib
-lopencv_core
-lopencv_imgcodecs
-lopencv_highgui
-lopencv_imgproc
SOURCES += main.cpp
mainwindow.cpp
FORMS += mainwindow.ui
主窗口.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
主.cpp
#include "mainwindow.h"
#include <QApplication>
#include <iostream>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
std::cout << "hello world - lalala" << std::endl;
return a.exec();
}
主窗口.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/opencv.hpp>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cv::Mat inputImage = cv::imread("/users/horse.jpg");
cv::imshow("test",inputImage);
}
MainWindow::~MainWindow()
{
delete ui;
}
主窗口.UI
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>797</width>
<height>525</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>350</x>
<y>330</y>
<width>113</width>
<height>32</height>
</rect>
</property>
<property name="text">
<string>done</string>
</property>
</widget>
<widget class="QGraphicsView" name="input">
<property name="geometry">
<rect>
<x>50</x>
<y>70</y>
<width>256</width>
<height>192</height>
</rect>
</property>
</widget>
<widget class="QGraphicsView" name="output">
<property name="geometry">
<rect>
<x>490</x>
<y>70</y>
<width>256</width>
<height>192</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>797</width>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuOpenCV">
<property name="title">
<string>OpenCV</string>
</property>
</widget>
<addaction name="menuOpenCV"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
我找到了解决问题的方法
https://qt-project.org/forums/viewthread/35646
我通过改变解决这个问题
/Users/ObiWang/Qt5.2.0/5.2.0-rc1/clang_64/mkspecs/macx-clang/qmake.conf
从 QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6 到
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9 则没有错误消息。
只有 10.9 个作品(10.6、10.7 和 10.8 都失败了)
我看到两个可能的问题:
在 .pro 文件中:
LIBS += -L/usr/local/lib
--> openCV 库是否在此目录中?(否则尝试添加带有另一个 -L 标志的 openCV 库目录)
从编译错误:
ld: symbol(s) not found for architecture x86_64
可能是,您拥有库的 32 位版本,而不是 64 位版本?(您可以使用文件命令进行检查:例如文件 opencv_core.so .)
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将OpenCV C++重写为EmguCV C#-如何使用指针
- OpenCV C++.快速计算混淆矩阵
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 在C++代码中包含opencv时,使用ctypes创建.so文件
- 哪些库可以通过Opencv调整曝光率
- 安装opencv失败-粘贴CMakeError.log的内容
- C++中的openCV Mat访问冲突
- OpenCV Android C++ imwrite not found
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- CV_OCL_RUN宏如何在OpenCV(版本3.4.5)的goodFeaturesToTrack实现中工作?
- Qt (OSX) and OpenCV errors
- 未显示 OpenCV 运行时"Errors"
- OpenCV - cudaimgproc errors
- OpenCV HOGDescriptor Errors