我有一个OpenCV程序,使用clang编译而没有错误,我希望尝试使用g ++ 5编译这个程序但是我收到以下错误:
ld: symbol(s) not found for architecture x86_64
我在尝试构建文件时使用的命令是:
g++-5 -std=c++11 -pthread main.cpp -o testcomp `pkg-config --cflags --libs opencv`
假设OpenCV库是32位但g ++ 5是为64位设计的,我是否正确?
如果我尝试使用以下命令编译代码,程序将成功构建:
g++ -std=c++11 -pthread main.cpp -o testComp `pkg-config --cflags --libs opencv`
我正在使用OSX并通过home-brew安装了g ++。
完整的编译错误如下:
Undefined symbols for architecture x86_64:
"cv::drawMatches(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, std::vector<cv::DMatch, std::allocator<cv::DMatch> > const&, cv::Mat&, cv::Scalar_<double> const&, cv::Scalar_<double> const&, std::vector<char, std::allocator<char> > const&, int)", referenced from:
processingThread(cv::Mat, int) in ccw6qwZp.o
"cv::FeatureDetector::create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
__static_initialization_and_destruction_0(int, int) in ccw6qwZp.o
"cv::DescriptorExtractor::create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
__static_initialization_and_destruction_0(int, int) in ccw6qwZp.o
"cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
_main in ccw6qwZp.o
"cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in ccw6qwZp.o
"cv::FeatureDetector::detect(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const", referenced from:
preProcessing() in ccw6qwZp.o
processingThread(cv::Mat, int) in ccw6qwZp.o
"cv::DescriptorMatcher::match(cv::Mat const&, cv::Mat const&, std::vector<cv::DMatch, std::allocator<cv::DMatch> >&, cv::Mat const&) const", referenced from:
processingThread(cv::Mat, int) in ccw6qwZp.o
"cv::DescriptorExtractor::compute(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat&) const", referenced from:
preProcessing() in ccw6qwZp.o
processingThread(cv::Mat, int) in ccw6qwZp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
根据添加了-Wl,-v
的评论进行的编译器输出:
collect2 version 5.2.0
/usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.11.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -weak_reference_mismatches non-weak -o testcomp -L/usr/local/lib -L/usr/local/Cellar/gcc5/5.2.0/lib/gcc/5/gcc/x86_64-apple-darwin15.0.0/5.2.0 -L/usr/local/Cellar/gcc5/5.2.0/lib/gcc/5/gcc/x86_64-apple-darwin15.0.0/5.2.0/../../.. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib -v /var/folders/nc/_drhkj6n3fnd1g3jmwq8mtm80000gn/T//ccfpdMCy.o -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_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lstdc++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem
@(#)PROGRAM:ld PROJECT:ld64-253.3.3
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
Library search paths:
/usr/local/lib
/usr/local/Cellar/gcc5/5.2.0/lib/gcc/5/gcc/x86_64-apple-darwin15.0.0/5.2.0
/usr/local/Cellar/gcc5/5.2.0/lib/gcc/5
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib
Framework search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/
Undefined symbols for architecture x86_64:
"cv::drawMatches(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> > const&, std::vector<cv::DMatch, std::allocator<cv::DMatch> > const&, cv::Mat&, cv::Scalar_<double> const&, cv::Scalar_<double> const&, std::vector<char, std::allocator<char> > const&, int)", referenced from:
processingThread(cv::Mat, int) in ccfpdMCy.o
"cv::FeatureDetector::create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
__static_initialization_and_destruction_0(int, int) in ccfpdMCy.o
"cv::DescriptorExtractor::create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
__static_initialization_and_destruction_0(int, int) in ccfpdMCy.o
"cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
_main in ccfpdMCy.o
"cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in ccfpdMCy.o
"cv::FeatureDetector::detect(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const", referenced from:
preProcessing() in ccfpdMCy.o
processingThread(cv::Mat, int) in ccfpdMCy.o
"cv::DescriptorMatcher::match(cv::Mat const&, cv::Mat const&, std::vector<cv::DMatch, std::allocator<cv::DMatch> >&, cv::Mat const&) const", referenced from:
processingThread(cv::Mat, int) in ccfpdMCy.o
"cv::DescriptorExtractor::compute(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat&) const", referenced from:
preProcessing() in ccfpdMCy.o
processingThread(cv::Mat, int) in ccfpdMCy.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status