macos - 在 OSX 上的 QT 中设置 OpenCV

标签 macos qt opencv

我正在尝试设置 OpenCV 以在 OSX 10.7.5/MacbookPro 2.5 Ghz Intel Core 2 Duo 上使用 QT。我在这里看到了一些相关问题( How to link opencv in QtCreator and use Qt libraryHow do you set up OpenCV with QT in OSX? ),但没有太多细节。在 QT 站点和我的网络搜索中,所有信息似乎都是关于 Windows 或 Linux 的。


我在下面列出了我的设置和代码。当我运行代码时出现错误::-1: error: symbol(s) not found for architecture x86_64

这是否意味着它找不到东西是因为路径错误或者因为我可能已经为 x86_32 构建了 openCV?有没有办法检查后者?我不太了解部分配置和设置过程。


更新 2

控制台输出如下 - 也许错误很明显?

02:44:38: Running steps for project RP_openCV_01...
02:44:38: Configuration unchanged, skipping qmake step.
02:44:38: Starting: "/usr/bin/make" 
clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o RP_openCV_01 main.o   -L/usr/local/lib -1ibopencv_core.2.4.6,dylib -1ibopencv_imgproc.2.4.6.dylib -F/Users/rise/Qt5.0.2/5.0.2/clang_64/lib -framework QtCore 
clang: warning: argument unused during compilation: '-1ibopencv_core.2.4.6,dylib'
clang: warning: argument unused during compilation: '-1ibopencv_imgproc.2.4.6.dylib'
Undefined symbols for architecture x86_64:
  "cv::_InputArray::_InputArray(cv::Mat const&)", referenced from:
      _main in main.o
  "cv::namedWindow(std::string const&, int)", referenced from:
      _main in main.o
  "cv::Mat::deallocate()", referenced from:
      _main in main.o
  "cv::imread(std::string const&, int)", referenced from:
      _main in main.o
  "cv::imshow(std::string const&, cv::_InputArray const&)", referenced from:
      _main in main.o
  "cv::waitKey(int)", referenced from:
      _main in main.o
  "cv::fastFree(void*)", referenced from:
      _main in main.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: *** [RP_openCV_01] Error 1
02:44:38: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project RP_openCV_01 (kit: Desktop Qt 5.0.2 clang 64bit)
When executing step 'Make'

我目前拥有的(tl;dr):

  • 从源代码构建并安装最新版本的 openCV (2.4.6),并使用一些命令行程序对其进行测试。

  • 安装了最新版本的 QT (5.1) 并能够运行所有示例等。

  • 指定项目文件中的路径(下)

QT       += core
QT       -= gui

TARGET = RP_openCV_01
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app
SOURCES += main.cpp

INCLUDEPATH += /usr/local/include\
LIBS += -L/usr/local/lib
  • 尝试在项目设置中指定路径(如下)。我添加了 /usr/local/include/usr/local/lib

enter image description here

main.cpp 中的简单示例代码

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

int main() {

    // read an image
    cv::Mat image= cv::imread("dog.jpg");
    // create image window named "My Image"
    cv::namedWindow("My Image");
    // show the image on window
    cv::imshow("My Image", image);
    // wait key for 5000 ms
    cv::waitKey(5000);

    return 1;
}

更新 1

我根据教程尝试的另一件事是在 QT 配置文件中指定库(如下图所示)。虽然该教程适用于 Windows,但我不知道 OSX 是否不同或有何不同。在 Windows 示例中,它是 -1ibopencv_core246d 我尝试过使用和不使用分隔句点但没有“d”。当然一个lib的全称是“libopencv_core.2.4.6.dylib”等

这些重要的细节总是让我感到困惑,但在教程中通常假设人们知道这些东西。

 LIBS += -L/usr/local/lib \
     -1ibopencv_core.2.4.6 \
     -1ibopencv_imgproc.2.4.6 \
     -1ibopencv_features2d.2.4.6 \
     -1ibopencv_highgui.2.4.6

enter image description here

最佳答案

只是一个天真的错误

正确的声明是:

LIBS += -L/usr/local/lib \
     -lopencv_core \
     -lopencv_imgproc \
     -lopencv_features2d\
     -lopencv_highgui

关于macos - 在 OSX 上的 QT 中设置 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17518408/

相关文章:

macos - 如何为支持 Cocoa/XCode 的 OSX 10.8 安装 VTK 6.1?

c++ - 操作系统 : Symbols not found for architecture i386

c++ - 如何在 Qt 中为矩阵类定义 [ ][ ] 运算符?

visual-studio-2010 - OpenCV 程序无法启动,因为 Visual Studio 2010 中缺少 MSVCP110D.dll

java - 在 Mac 上通过 Java 使用数据库

windows - 给eclipse更多的堆空间来编译项目?

Ubuntu 14.04 上的 QT 应用程序

c++ - (QT/kdelib) 如何知道 KTerminalInterface 中命令的结束?

c++ - 如何在 cpp 中编写 python sys.stdout.write

c# - ARKit 中是否公开了 pnp 求解器,或者如何使用 EmguCV c# 包装器在 Unity3D 项目中使用 opencv 的 SolvePnP 函数