Error when using imshow on OS X - c++

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

Related

OpenCV4 on XCode — opencv2/core.hpp not found

so I've been trying to install OpenCV with C++ on my mac using this tutorial: https://medium.com/#jaskaranvirdi/setting-up-opencv-and-c-development-environment-in-xcode-b6027728003 but I keep getting this error on Xcode:
" 'opencv2/core.hpp' file not found "
I tried setting both Library Search Paths and Header Search Paths to recursive but it didn't change anything
I've also been getting this error on the terminal, I don't know if it's related. I think it's important to note that this isn't my first time trying to install opencv and I don't know if it's the old versions that keep messing with it. I tried to cleanup everything before installing this version but I'm not sure.
Undefined symbols for architecture x86_64:
"cv::namedWindow(cv::String const&, int)", referenced from:
_main in main-55ed98.o
"cv::String::deallocate()", referenced from:
cv::String::~String() in main-55ed98.o
cv::String::operator=(cv::String const&) in main-55ed98.o
"cv::String::allocate(unsigned long)", referenced from:
cv::String::String(char const*) in main-55ed98.o
"cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
_main in main-55ed98.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any suggestions on how to solve these issues please?

When I install Caffe on Mac, there is a fault "clang: warning: argument unused during compilation: '-pthread' "

I feel that all dependences are installed, and I want to install Caffe without GPU, but when I do make all, there is an error:
CXX src/caffe/util/upgrade_proto.cpp
AR -o .build_release/lib/libcaffe.a
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolch ain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_conv_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_lcn_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_lrn_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_pooling_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_relu_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_sigmoid_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_softmax_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn_tanh_layer.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchain/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn.o) has no symbols
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
clang: warning: argument unused during compilation: '-pthread'
Undefined symbols for architecture x86_64:
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
caffe::WindowDataLayer<float>::load_batch(caffe::Batch<float>*) in window_data_layer.o
caffe::WindowDataLayer<double>::load_batch(caffe::Batch<double>*) in window_data_layer.o
caffe::ReadImageToCVMat(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, bool) in io.o
"cv::imencode(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
caffe::ReadImageToDatum(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, int, int, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, caffe::Datum*) in io.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: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
I do not understand why this happens and it seems like my Xcode may have some problems? Could someone help me?
There are two separate things here:
"clang: warning: argument unused during compilation: '-pthread'" is an ignoreable (although annoying) compiler warning (not error) that you often get with MacOS clang, these days it has pthreads support builtin. Ignore it, or suppress it with -Wno-error=unused-command-line-argument
whereas "Undefined symbols for architecture x86_64: ... clang: error: linker command failed with exit code " is an actual error. Fix that. (Looks like a missing header file to me, so check your -I... include paths. I don't know Caffe so I can't comment more on that.)
make sure you install openCV before building caffe.
brew install -vd snappy leveldb gflags glog szip lmdb
# need the homebrew science source for OpenCV and hdf5
brew tap homebrew/science
brew install hdf5 opencv
please go threw caffe OS X Installation.
I had a similar problem as well. It could be the Makefile.config. Please check the paths you provided for PYTHON_INCLUDE and PYTHON_LIB.
I had given the brew python path to PYTHON_INCLUDE and system path to PYTHON_LIB. I also made sure that the caffe python was added to the python path before compiling.Hope this information is of help.

Linking Boost on iOS project. vtable for boost::filesystem::detail::utf8_codecvt_facet

I've managed to compile Swiften library for a iOS project, but now I'm having linking errors related to Boost library.
I've compiled Boost following these steps, the error I'm getting during linking is:
Undefined symbols for architecture arm64:
"vtable for boost::filesystem::detail::utf8_codecvt_facet", referenced from:
__GLOBAL__I_a in boost(path.o)
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've read some articles which suggest including some compilation params, but not sure which params or where should I put them. I've also reached this thread with no solution. Anyone else faced this issue? Anyone succeeded compiling and running Swiften for iOS? Any tip on the right direction would be much appreciated.
UPDATE 1
It seems filesystem and program_options libs share utf8_codecvt_facet object, and one was overriding the other while building boost. Finally, I managed to compile the whole Swiften library, but when I try to use it I'm getting more linking errors :( I get this error when I declare a JID object on my main class:
Undefined symbols for architecture armv7:
"Swift::StringPrep::getPrepared(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&,
Swift::StringPrep::Profile)", referenced from:
Swift::JID::nameprepAndSetComponents(std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&,
std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char> > const&, std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char> > const&) in JID.o

Unresolved symbol error with the soci library

I understand what an unresolved symbol error is, but I don't understand why I'm getting it in this particular situation with this particular library. Here is the output of the error.
Undefined symbols for architecture x86_64:
"soci::soci_error::soci_error(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
soci::type_conversion<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void>::from_base(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, soci::indicator, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in Inspector.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Note that I am using the following link flags:
-L/usr/local/lib -lsoci_core -lsoci_postgresql -lpq -ldl
Note also that references to other symbols (e.g., the soci::session constructor and destructor) are being resolved.
What am I doing wrong? Is there another soci library that I should also be linking against?
EDIT: Note that I am working on Mac OS X, and have tried both the installation through homebrew (via brew install soci --with-pg), and the standalone installations of 3.2.2 and 3.2.1.
I don't know why this solved the error, but changing from libc++ to libstdc++ resolved it.

Build error using Featured2D in OpenCV with XCode

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.