I have an error of Undefined symbol cv::LineIterator::LineIterator(cv::Mat const&, cv::Point_<int>, cv::Point_<int>, int, bool). So I've stumbled upon this issue that I am not sure if it is a bug but I cannot figure out how to fix it or what I am doing wrong.
I am trying to compile a library that uses OpenCV 4.5.1 that I compiled myself for a Mac Catalyst architecture. The OpenCV library I compiled for both arm64 and x86_64 architectures
$ lipo -info opencv2macos.framework/opencv2macos
Architectures in the fat file: opencv2macos.framework/opencv2macos are: x86_64 arm64
However when I try to compile a library that instantiates a cv::LineIterator line_it(mask, cv::Point(2, 4), cv::Point(10, 20), 8, false) I get this error:
Undefined symbols for architecture arm64:
"cv::LineIterator::LineIterator(cv::Mat const&, cv::Point_<int>, cv::Point_<int>, int, bool)", referenced from:
getPointCorresp(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, cv::Mat const&, std::__1::vector<cv::Point_<float>, std::__1::allocator<cv::Point_<float> > > const&, cv::Mat const&, bool) in CMAUtil.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any idea what could be going wrong here?
After more researching and investigating, the issue was because I was using 2 opencv2 frameworks, one compiled for iOS devices and one compiled for Mac Catalyst.
When I compiled the framework for Catalyst I used a flag to change the name of the framework from opencv2 to opencv2macos which meant that the include headers were supposed to be like #include<opencv2macos/core.hpp>. However when I looked into a few more headers I could find #include<opencv2/imgproc.hpp> which explains why my project was somehow linking to the wrong framework - it was linking to code from opencv2.framework instead of opencv2macos.framework and because the two were different versions (the first one was 4.1.1 and the second was 4.5.1) I guess there was discrepancy within the implementation.
Related
I use g++-12 and qt6 installed via homebrew.
At linking my executable on macos, I get this error:
Undefined symbols for architecture x86_64:
"__ZN9QMetaType25registerConverterFunctionERKSt8functionIFbPKvPvEES_S_", referenced from:
The function it's not finding is:
QMetaType::registerConverterFunction(std::function<bool (void const*, void*)> const&, QMetaType, QMetaType)
but in the QtCore lib, the closest corresponding function I can find is:
QMetaType::registerConverterFunction(std::__1::function<bool (void const*, void*)> const&, QMetaType, QMetaType)
Notice the ::__1 namespace
I never got into this kind of problem. Any clue where this comes from?
(the codes compile fine on linux and I can even cross compile it on linux for windows via mingw)
For my application running on iPhone I am using OpenCV using opencv2.framework in Xcode with objective-c and C++ as languages. My development worked well until I wanted to introduce cv::Tracker that is not included in opencv2.framework but part of opencv_contrib.
I rebuilt and installed from the source opencv-3.4.0 with opencv_contrib-master using CMake and terminal commands make and install.
In Xcode I have set
HEADER_SEARCH_PATHS = /usr/local/include and
LIBRARY_SEARCH_PATHS = /usr/local/lib
When compiling I get a long list of errors of the style:
Undefined symbols for architecture x86_64:
"cv::error(int, cv::String const&, char const*, char const*, int)",
referenced from:
cv::Mat::Mat(int, int, int, void*, unsigned long) in OpenCVRenderer.o
"cv::Mat::operator=(cv::Scalar_<double> const&)", referenced from:
cv::Mat::Mat(int, int, int, cv::Scalar_<double> const&) in
OpenCVRenderer.o
cv::Mat::Mat(cv::Size_<int>, int, cv::Scalar_<double> const&) in
OpenCVRenderer.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in OpenCVRenderer.o
"cv::polylines(cv::_InputOutputArray const&, cv::_InputArray const&,
bool, cv::Scalar_<double> const&, int, int, int)", referenced from:
.
.
.
I set OTHER_LDFLAGS = (list of opencv dylibs) preceeded by a "-" sign
Now I get errors as if the libraries are not found while there are in fact in /usr/local/lib
For example I get:
ld: library not found for -libopencv_core.3.4.0.dylib
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Any help?
Thank you.
There are a couples of problems with your settings.
You only specified where to find the libraries, not opencv2.framework. You should either specify framework_search_path (and link your framework to the project) or link the corresponding libraries.
You said you were building an iPhone app, yet the error says Undefined symbols for architecture x86_64:. That is, either you built your app for phone simulator or for mac. Yet, your framework is most likely built for iPhone architecture (armv7 and arm64). This case, you need to rebuild the framework. If you build iPhone app, do not link any dylib libraries in /usr/local/lib/.
Note that libopencv_core.3.4.0.dylib is part of normal opencv so the error has nothing to do with opencv_contrib (yet).
I have setup OpenCV2 in XCode but unfortunately imshow does not work:
Undefined symbols for architecture x86_64:
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", 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)
I am running OS X 10.8.4 with latest XCode.
I have attached a few images below to show the setup in XCode and the libraries.
So far it seems that other functions work fine with OpenCV, except this.
I'm going to go out on a limb and say that you compiled OpenCV2 with libstdc++, and are now compiling your application with libc++ support.
You need to compile OpenCV2 with the same C++ library, otherwise it will not be able to link.
if you do an nm of the OpenCV2 library, if it was compiled with libstdc++, it will look like:
cv::imshow(std::string const&, cv::_InputArray const&)
while if it was compiled with libc++, it would look like:
cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)
to get the demangled symbol do:
nm library | c++filt | grep cv::imshow
I'm implementing echoprint in my iOS 6 app but when I compile my project it gives me errors from Codegen.
Undefined symbols for architecture i386:
"Codegen::Codegen(float const*, unsigned int, int)", referenced from:
codegen_wrapper(float const*, int) in Codegen_wrapper.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
How to compile and run Codegen on iOS is explained here:
Echoprint iOS Missing Framework
Since simulator in XCode uses i386 processor, it fails to link it with object which is compiled in arm7.
While compiling libechoprint-codegen-ios.a choose iPhone Simulator as target, then you will have it compiled in i386. Then it will successfully link it. You can learn whether it is compiled in arm7 or i386 by typing
lipo -info path/libechoprint-codegen-ios.a
source: http://www.verious.com/qa/linker-error-for-echoprint-in-ios/
I have been fighting with an build error when using Features2D in OpenCV which i cannot figure out why.
OpenCV version: 2.4.3 (MacPorts)
Compile arch: 64-bit intel
C Language Dialect: GNU99
C++ Language Dialect: GNU++11
C++ Standard Library: libstdc++
The build error:
Undefined symbols for architecture x86_64:
"cv::FeatureDetector::detect(cv::Mat const&, std::__debug::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const", referenced from:
analysis::openCvStitching() in analysis.o
"cv::DescriptorMatcher::match(cv::Mat const&, cv::Mat const&, std::__debug::vector<cv::DMatch, std::allocator<cv::DMatch> >&, cv::Mat const&) const", referenced from:
analysis::openCvStitching() in analysis.o
"cv::DescriptorExtractor::compute(cv::Mat const&, std::__debug::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat&) const", referenced from:
analysis::openCvStitching() in analysis.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This is how i create a pointer to the FeatureDetector and DescriptorExtractor:
Ptr<FeatureDetector> surfDetector = FeatureDetector::create(type);
Ptr<DescriptorExtractor> surfExtractor = DescriptorExtractor::create(type);
Have you tried deleting _GLIBCXX_DEBUG=1 and/or _GLIBCXX_DEBUG_PEDANTIC=1 from the preprocessor flags in your project settings? opencv2 c++ api is somewhat bad in its use of STL templates in the API functions, which may cause linker errors or crashes if your version of the standard libraries or compiler flags do not match exactly with what's used when it was compiled.