我的系统版本是10.11.6
opencv版本:2.4.13
gcc-v的输出是
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
我正在尝试在.pro文件中运行由QT创建者中的其他人编写的项目,包括:
QMAKE_CXXFLAGS -= -stdlib=libc++
QMAKE_CXXFLAGS += -stdlib=libstdc++
QMAKE_LFLAGS += -stdlib=libstdc++
所以,这个项目中的代码使用libstdc ++,如果我尝试使用libc ++,它将在构建期间输出错误。
但即使我使用libstdc ++,它仍然会出现以下错误消息:
clang: warning: libstdc++ is deprecated; move to libc++
Undefined symbols for architecture x86_64:
"cv::namedWindow(std::string const&, int)", referenced from:
tvseg::cuda::cvImageShow(float*, int, int, int, char const*) in cvimageshow.o
"cv::imread(std::string const&, int)", referenced from:
tvseg::SegmentationImpl::loadImage(std::string) const in segmentationimpl.o
tvseg::Scribbles::loadScribbleImage(std::string, cv::Mat, tvseg::Dim2) in scribbles.o
"cv::imshow(std::string const&, cv::_InputArray const&)", referenced from:
tvseg::cuda::cvImageShow(float*, int, int, int, char const*) in cvimageshow.o
"cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)", referenced from:
tvseg::SegmentationImpl::saveImage(std::string, cv::Mat, bool, bool) const in segmentationimpl.o
tvseg::Scribbles::saveScribbleImage(std::string, cv::Mat, tvseg::Dim2) const in scribbles.o
"cv::Exception::Exception(int, std::string const&, std::string const&, std::string const&, int)", referenced from:
cv::Vec<unsigned char, 3>& cv::Mat::at<cv::Vec<unsigned char, 3> >(int, int) in cvimageshow.o
cv::Vec<float, 3>& cv::Mat::at<cv::Vec<float, 3> >(int, int) in cvimageshow.o
float& cv::Mat::at<float>(int, int) in cvimageshow.o
int& cv::Mat::at<int>(int, int) in cvimageshow.o
bool& cv::Mat::at<bool>(int, int) in cvimageshow.o
float* cv::Mat::ptr<float>(int, int, int) in cvimageshow.o
cv::Vec<float, 3>& cv::Mat::at<cv::Vec<float, 3> >(int) in kmeanscpu.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: *** [tvseg] Error 1
10:09:05: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project tvseg (kit: Desktop Qt 5.3 clang 64bit)
When executing step "Make"
10:09:05: Elapsed time: 02:00.
我已设置QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.11
lipo -info libopencv_core.dylib的输出是
Non-fat file: libopencv_core.dylib is architecture: x86_64
otool -L libopencv_core.dylib的输出是
libopencv_core.dylib:
/usr/local/opt/opencv/lib/libopencv_core.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.8)
/usr/local/opt/tbb/lib/libtbb.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.4.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
这是另一件我不知道是否重要的事情,在.pro文件中包含这个
LIBS += $$system(PKG_CONFIG_PATH=/usr/local/opt/opencv/lib/pkgconfig/ pkg-config opencv --libs-only-other)
我已将其更改为:
LIBS += $$system(PKG_CONFIG_PATH=/usr/local/opt/opencv/lib/pkgconfig/ pkg-config opencv --libs)
因为如果使用--lib-only-other,将会有更多的opencv函数无法识别。 opencv.pc文件是:
# Package Information for pkg-config
prefix=/usr/local/Cellar/opencv/2.4.13.1
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 2.4.13.1
Libs: -L${exec_prefix}/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab /usr/local/lib/libtbb.dylib
Cflags: -I${includedir_old} -I${includedir_new}
我认为我收到此错误是因为我使用libc ++构建opencv,但我不知道如何使用libstdc ++,而qt creator有此警告消息:
clang: warning: libstdc++ is deprecated; move to libc++
这是否意味着qt creator不支持libstdc ++,或者我可以更改某些设置?
更新:我正在使用brew安装opencv,这次我试图添加-stdlib = libstdc ++,最终输出是:
==> Entering interactive mode
Type `exit' to return and finalize the installation
Install to this prefix: /usr/local/Cellar/opencv/2.4.13.1
bash-3.2$ exit
exit
Error: Empty installation
/usr/local/Homebrew/Library/Homebrew/formula_installer.rb:617:in `build'
/usr/local/Homebrew/Library/Homebrew/formula_installer.rb:258:in `install'
/usr/local/Homebrew/Library/Homebrew/cmd/reinstall.rb:45:in `reinstall_formula'
/usr/local/Homebrew/Library/Homebrew/cmd/reinstall.rb:18:in `block in reinstall'
/usr/local/Homebrew/Library/Homebrew/cmd/reinstall.rb:13:in `each'
/usr/local/Homebrew/Library/Homebrew/cmd/reinstall.rb:13:in `reinstall'
/usr/local/Homebrew/Library/Homebrew/brew.rb:94:in `<main>'