【发布时间】:2013-12-06 23:28:57
【问题描述】:
我想在 mac 上的 qt 中使用 openCV 库。我读了很多关于如何在 qt(我有 5.1)中配置 pro 文件以使用 OpenCV,但对我没有任何作用。 我做了什么:
1) sudo port install opencv
2) sudo port install pkg-config
3) add to *.pro file: LIBS += `pkg-config --libs opencv`
但我只得到错误:
Target: x86_64-apple-darwin13.0.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -headerpad_max_install_names -macosx_version_min 10.9.0 -o opencv_pokus3.app/Contents/MacOS/opencv_pokus3 -L/opt/local/lib -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk main.o mainwindow.o moc_mainwindow.o -lopencv_core -lopencv_highgui -framework QtWidgets -framework QtGui -framework QtCore -framework OpenGL -framework AGL -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.osx.a -F/Applications/Qt5.1.1/5.1.1/clang_64/lib
Undefined symbols for architecture x86_64:
"cv::imread(std::string const&, int)", referenced from:
_main in main.o
"std::allocator<char>::allocator()", referenced from:
_main in main.o
"std::allocator<char>::~allocator()", referenced from:
_main in main.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
_main in main.o
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", 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: *** [opencv_pokus3.app/Contents/MacOS/opencv_pokus3] Error 1
12:56:15: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project opencv_pokus3 (kit: Desktop Qt 5.1.1 clang 64bit)
When executing step 'Make'
12:56:15: Elapsed time: 00:00.
我尝试将步骤 3 更改为:
LIBS += -L/opt/local/lib \
-lopencv_calib3d \
-lopencv_contrib \
-lopencv_core \
-lopencv_features2d \
...
但是,不幸的是它得到了相同的结果......
PS:我可以通过终端编译openCV helloWorld程序:
g++ `pkg-config --libs --cflags opencv` -o helloWorld helloOpenCV.cpp
or
clang++ `pkg-config --libs --cflags opencv` -o helloWorld hello.cpp
一切正常……
我的配置: OSX 10.9, QT 5.1.1, opencv 2.4.7 通过 macports 安装, pkg-config 0.28 通过 macports 安装,
简单的hello world程序:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
...
char var;
cv::Mat img;
img = cv::imread("./imgres.jpg");
cv::namedWindow("Image");
cv::imshow("Image", img);
std::cin >> var;
...
你有什么提示吗,怎么办?
编辑:从终端列出:
pkg-config --libs opencv
/opt/local/lib/libopencv_calib3d.dylib /opt/local/lib/libopencv_contrib.dylib /opt/local/lib/libopencv_core.dylib /opt/local/lib/libopencv_features2d.dylib /opt/local/lib/libopencv_flann.dylib /opt/local/lib/libopencv_gpu.dylib /opt/local/lib/libopencv_highgui.dylib /opt/local/lib/libopencv_imgproc.dylib /opt/local/lib/libopencv_legacy.dylib /opt/local/lib/libopencv_ml.dylib /opt/local/lib/libopencv_nonfree.dylib /opt/local/lib/libopencv_objdetect.dylib /opt/local/lib/libopencv_photo.dylib /opt/local/lib/libopencv_stitching.dylib /opt/local/lib/libopencv_superres.dylib /opt/local/lib/libopencv_ts.a /opt/local/lib/libopencv_video.dylib /opt/local/lib/libopencv_videostab.dylib
pkg-config --libs-only-L opencv
这应该是个问题吗?为什么 -L 是空的?
【问题讨论】:
标签: c++ macos qt opencv macports