我正在尝试设置OpenCV
在QT
OSX 10.7.5/MacbookPro 2.5 Ghz Intel Core 2 Duo 上使用。我在这里看到了一些相关的问题(How to link opencv in QtCreator and use Qt library and How 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
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”的位置。当然,一个库的全名是“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