I'm trying to link static libraries for the OpenCV library into my project, yet I get the error:
Undefined symbols for architecture armv7:
"__ZN2cv9ExceptionC1EiRKSsS2_S2_i", referenced from:
__ZL16icvGenerateQuadsPP8CvCBQuadPP10CvCBCornerP12CvMemStorageP5CvMati in libopencv_calib3d.a(calibinit.o)
_cvFindChessboardCorners in libopencv_calib3d.a(calibinit.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have no ideas what that symbol "ZN2cv9ExceptionC1EiRKSsS2_S2_i" should be, that string of Letters found in any source or header file I used to build the static libraries.
Could anyone who's more experienced with the linker explain these errors to me?
EDIT: 01.07. haven't solved this yet, just opted out of checkerboard-detection with calib3d and went for a less complicated circle detection using features2D that gives no linking error.
Most probably you put OpenCV libs in wrong order. Try the following order in your link list:
opencv_contrib opencv_legacy opencv_videostab opencv_photo opencv_stitching opencv_objdetect opencv_video opencv_ml opencv_calib3d opencv_features2d opencv_highgui opencv_flann opencv_imgproc opencv_core
You can use c++filt to unmangle the undefined symbol to find the actual function name.
$ c++filt.exe __ZN2cv9ExceptionC1EiRKSsS2_S2_i
cv::Exception::Exception(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)
Then you'll have to identify which source file contains this function and link in the library corresponding to that.
Related
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 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.
I would like to use the Library cpp-netlib for a C++ project. Therefore I installed the boost library with the help of homebrew (OS is Mac OS X 10.8). Then I downloaded cpp-netlib from the projects homepage, used cmake to create the Makefile for g++ and successfully applied make.
"make test" passed all its tests. Then I copied the include folder of cpp-netlib into the boost directory.
So here is when the trouble began:
I tried to compile the documentation's first example http-client but couldn't get it to work. When I used
g++ test.cpp -o out -I/usr/local/Cellar/boost/1.53.0/include
-L/usr/local/Cellar/boost/1.53.0/lib
-lboost_system-mt -lboost_filesystem-mt -lboost_thread-mt
I received these linker errors:
Undefined symbols for architecture x86_64:
"boost::network::uri::detail::parse(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::network::uri::detail::uri_parts<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)", referenced from:
boost::network::uri::uri::parse() in ccs87Dq3.o
"boost::network::http::impl::normal_delegate::normal_delegate(boost::asio::io_service&)", referenced from:
boost::network::http::impl::connection_delegate_factory<boost::network::http::tags::http_async_8bit_udp_resolve>::new_connection_delegate(boost::asio::io_service&, bool, boost::optional<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, boost::optional<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >)in ccs87Dq3.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
I really used the search function but I couldn't find any solution for my problem. What am I doing wrong?
Thanks a lot!
After building cpp-netlib (>=0.9.3) there should 3 static libraries:
libcppnetlib-client-connections.a
libcppnetlib-server-parsers.a
libcppnetlib-uri.a
When building your http-client project, you should specify a library path for cpp-netlib (-L) and libraries to link (-l) against: cppnetlib-uri and libcppnetlib-client-connections.
Here is what worked for me. You will need to modify certain parts to deal with different versions of boost, different install paths, and so on.
g++ -o demo \
demo.cpp \
-lcppnetlib-uri \
-lcppnetlib-server-parsers \
-lcppnetlib-client-connections \
-lboost_thread-mt \
-lboost_system-mt \
-lssl \
-lcrypto \
-I/usr/local/include \
-L/usr/local/lib
If you are writing server-side code then I imagine you will also need to include -lcppnetlib-server-parsers.
In case someone is having the same issue with visual studio, provide the library input to the linker.
Project properties > Linker > input >
libcppnetlib-client-connectionsd.lib
libcppnetlib-urid.lib
for Debug configuration and
libcppnetlib-client-connections.lib
libcppnetlib-uri.lib
for Release configuration.
Specify the Library path here,
Project properties > Linker > general > Additional include directories
The following library files exist:
cls /usr/local/Cellar/boost/1.51.0/lib $ ls libboost_program*
libboost_program_options-mt.a libboost_program_options-mt.dylib
I include the following header with #include <boost/program_options.hpp>:
cls /usr/local/Cellar/boost/1.51.0/include $ ls boost/program_options.hpp
boost/program_options.hpp
I try to link the libraries with
-lboost_program_options-mt
-L/usr/local/Cellar/boost/1.51.0/lib
(I assume that the name of the library is derived from the file name minus the "lib" and the file ending. If I try the name boost_program_options (without -mt), I get ld: library not found for -lboost_program_options)
This is my main function using the library:
#include <boost/program_options.hpp>
#include <iostream
int main(int argc, char **argv) {
namespace opts = boost::program_options;
opts::options_description desc("EnsembleClustering options");
desc.add_options()
("hello", "produce greeting");
opts::variables_map vmap;
opts::store(opts::parse_command_line(argc, argv, desc), vmap);
opts::notify(vmap);
if (vmap.count("hello")) {
std::cout << "Hello World" << std::endl;
}
}
Why does this setup give me a symbol(s) not found error?
make all
Building target: EnsembleClustering-DPar
Invoking: MacOS X C++ Linker
/usr/local/bin/g++-4.7 -L"/Users/cls/workspace/STINGER/OpenMP Debug" -L"/Users/cls/workspace/gtest/lib" -L/usr/local/Cellar/log4cxx/0.10.0/lib -L/usr/local/Cellar/boost/1.51.0/lib -fopenmp -std=c++11 -o "EnsembleClustering-DPar" ./src/scoring/EdgeScoring.o ./src/scoring/ModularityScoring.o ./src/overlap/test/OverlapGTest.o ./src/overlap/Overlapper.o ./src/overlap/RegionGrowingOverlapper.o ./src/matching/Matcher.o ./src/matching/Matching.o ./src/matching/ParallelMatcher.o ./src/io/test/InputGTest.o ./src/io/CSVWriter.o ./src/io/GraphFromAdjacencies.o ./src/io/GraphIO.o ./src/io/GraphReader.o ./src/io/METISGraphReader.o ./src/io/METISParser.o ./src/io/METISToGraph.o ./src/graph/test/GraphGTest.o ./src/graph/test/STINGERGTest.o ./src/graph/Graph.o ./src/graph/GraphGenerator.o ./src/ensemble/test/EnsembleGTest.o ./src/ensemble/EnsembleClusterer.o ./src/coarsening/test/CoarseningGTest.o ./src/coarsening/ClusterContracter.o ./src/coarsening/ClusteringProjector.o ./src/coarsening/Contracter.o ./src/coarsening/GraphContraction.o ./src/coarsening/MatchingContracter.o ./src/clustering/test/ClusteringGTest.o ./src/clustering/base/Clustering.o ./src/clustering/base/ClusteringGenerator.o ./src/clustering/base/Modularity.o ./src/clustering/base/QualityMeasure.o ./src/clustering/algo/test/ClusteringAlgoGTest.o ./src/clustering/algo/Clusterer.o ./src/clustering/algo/LabelPropagation.o ./src/clustering/algo/ParallelAgglomerativeClusterer.o ./src/aux/test/AuxGTest.o ./src/aux/Noise.o ./src/aux/RandomInteger.o ./src/aux/RandomProbability.o ./src/aux/Timer.o ./src/EnsembleClustering.o -lSTINGER -lgtest -llog4cxx -lboost_program_options-mt
Undefined symbols for architecture x86_64:
"boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)", referenced from:
boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*) in EnsembleClustering.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [EnsembleClustering-DPar] Error 1
EDIT: Checking the library files with lipo gives
cls /usr/local/Cellar/boost/1.51.0/lib $ lipo -detailed_info libboost_program_options-mt.a libboost_program_options-mt.dylib
input file libboost_program_options-mt.a is not a fat file
input file libboost_program_options-mt.dylib is not a fat file
Non-fat file: libboost_program_options-mt.a is architecture: x86_64
Non-fat file: libboost_program_options-mt.dylib is architecture: x86_64
I'd like to link the static library.
Read the error message
Undefined symbols for architecture x86_64:
"boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&)", referenced from:
boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*) in EnsembleClustering.o
It very clearly says, missing symbol std::__debug::vector, note that the std::__debug namespace is key here. I suspect you've built your source code using iterator debugging with -D_GLIBCXX_DEBUG but are attempting to link against a library that hasn't, such as boost program options. You didn't show us how you built your translation units, so here is a sscce:
$ g++-4.8 -std=c++11 -O2 -pthread main.cpp -D_GLIBCXX_DEBUG -lboost_program_options && ./a.out
/tmp/cca1jwUx.o: In function `boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*)':
main.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcEC2EiPKPKc[_ZN5boost15program_options25basic_command_line_parserIcEC5EiPKPKc]+0x319): undefined reference to `boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::string, std::allocator<std::string> > const&)'
collect2: error: ld returned 1 exit status
There are a few ways to solve this
remove the -DGLIBCXX_DEBUG flag from translation units including the program options headers.
consult your boost package maintainer to see if they offer a version built with -D_GLIBCXX_DEBUG. Some variants on Linux do, you might ask around the MacPorts or brew users mailing lists.
Since you're specifying the location for includes, libraries and providing the appropriate .dylib, the only problem I can think of is that the library that you're linking to doesn't have an x86_64 arch in it.
Try checking the library with either file or lipo. If it doesn't show x86_64, then that's the problem.
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.