opencv Apple Mach-O Linker - c++

I am trying to run an opencv project by xcode6.
This tutorial is cool and works for me, first, without xcode: The application runs perfectly after make'ing.
Now, I want to use Xcode 6 as development environment.
But I get an Apple Mach-O Linker error.
Build Settings are:
Header Search Paths : /usr/local/include (non-recursive)
Library Search Paths: /urs/local/lib (non-recursive)
Build Phases > Link Binary With Libraries:
Libc++.dylib
This is the error:
Ld /Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Products/Debug/HelloWorld normal x86_64
cd /Users/XXX/Desktop/make/CLTproject/HelloWorld/HelloWorld
export MACOSX_DEPLOYMENT_TARGET=10.10
/Applications/Xcode-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Products/Debug -L/usr/local/lib -F/Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Products/Debug -filelist /Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/HelloWorld.LinkFileList -mmacosx-version-min=10.10 -stdlib=libc++ -lc++ -Xlinker -dependency_info -Xlinker /Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Intermediates/HelloWorld.build/Debug/HelloWorld.build/Objects-normal/x86_64/HelloWorld_dependency_info.dat -o /Users/XXX/Library/Developer/Xcode/DerivedData/HelloWorld-ejnkjggujedpyibjbhvocitoxxaj/Build/Products/Debug/HelloWorld
Undefined symbols for architecture x86_64:
"cv::namedWindow(cv::String const&, int)", referenced from:
_main in main.o
"cv::GaussianBlur(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)", referenced from:
_main in main.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in main.o
"cv::Mat::copySize(cv::Mat const&)", referenced from:
cv::Mat::operator=(cv::Mat const&) in main.o
"cv::String::deallocate()", referenced from:
cv::String::~String() in main.o
"cv::String::allocate(unsigned long)", referenced from:
cv::String::String(char const*) in main.o
"cv::imread(cv::String const&, int)", referenced from:
_main in main.o
"cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
_main in main.o
"cv::waitKey(int)", referenced from:
_main in main.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in main.o
"cv::Mat::copyTo(cv::_OutputArray const&) const", referenced from:
cv::Mat::clone() const in main.o
"vtable for cv::_InputArray", referenced from:
cv::_InputArray::_InputArray() in main.o
cv::_InputArray::_InputArray(cv::Mat const&) in main.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for cv::_OutputArray", referenced from:
cv::_OutputArray::_OutputArray(cv::Mat&) in main.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any Idea?
Thanks,
isicom

Just to give some light to everybody in the same problem. I added all libraries and worked fine for me. I stayed in the libc++ with no building errors.

Related

What is causing GoogleTest Link Error on macOS Mojave? [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 3 years ago.
I'm not sure if I have a problem w/ requiring additional arguments to cmake, or a problem with my own Makefiles. I am trying to build and install googletest for use in one of my projects. I am running on macOS mojave, with cmake installed via Homebrew. To install googletest, I have done the following:
git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake ..
make
make install
I compile my source and test files. Here is an example command that gets generated by the Makefile for compiling a file named Point2d.cpp:
clang++ -arch x86_64 -c -std=c++11 -stdlib=libc++ -O2 -I /usr/local/include -c -o ../build/core/Point2d.o core/Point2d.cpp
I then try to link all my object files. Here is the command generated by the makefile (where main.o is the object file containing the main function for running the tests):
clang++ -arch x86_64 ../build/core/Point2d.o ../build/PointTest.o ../build/main.o -o ../bin/test -L /usr/local/lib
Resulting link error:
Undefined symbols for architecture x86_64:
"testing::InitGoogleTest(int*, char**)", referenced from:
_main in main.o
"testing::Test::SetUp()", referenced from:
vtable for Point2dTests_Constructors_Test in PointTest.o
"testing::Test::TearDown()", referenced from:
vtable for Point2dTests_Constructors_Test in PointTest.o
"testing::Test::Test()", referenced from:
testing::internal::TestFactoryImpl<Point2dTests_Constructors_Test>::CreateTest() in PointTest.o
"testing::Test::~Test()", referenced from:
Point2dTests_Constructors_Test::~Point2dTests_Constructors_Test() in PointTest.o
Point2dTests_Constructors_Test::~Point2dTests_Constructors_Test() in PointTest.o
"testing::Message::Message()", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::UnitTest::GetInstance()", referenced from:
_main in main.o
"testing::UnitTest::Run()", referenced from:
_main in main.o
"testing::internal::AssertHelper::AssertHelper(testing::TestPartResult::Type, char const*, int, char const*)", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::internal::AssertHelper::~AssertHelper()", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::internal::GetTestTypeId()", referenced from:
__GLOBAL__sub_I_PointTest.cpp in PointTest.o
"testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, testing::internal::CodeLocation, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)", referenced from:
__GLOBAL__sub_I_PointTest.cpp in PointTest.o
"testing::internal::GetBoolAssertionFailureMessage(testing::AssertionResult const&, char const*, char const*, char const*)", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"testing::internal::IsTrue(bool)", referenced from:
testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in PointTest.o
testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in PointTest.o
"testing::internal::GTestLog::GTestLog(testing::internal::GTestLogSeverity, char const*, int)", referenced from:
testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in PointTest.o
testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in PointTest.o
"testing::internal::GTestLog::~GTestLog()", referenced from:
testing::internal::SuiteApiResolver<testing::Test>::GetSetUpCaseOrSuite(char const*, int) in PointTest.o
testing::internal::SuiteApiResolver<testing::Test>::GetTearDownCaseOrSuite(char const*, int) in PointTest.o
"testing::internal::AssertHelper::operator=(testing::Message const&) const", referenced from:
Point2dTests_Constructors_Test::TestBody() in PointTest.o
"typeinfo for testing::Test", referenced from:
typeinfo for Point2dTests_Constructors_Test in PointTest.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[1]: *** [../bin/test] Error 1
make: *** [test] Error 2
Solved. Please see the comments of the question, posted by #AlexDenisov

Linking external code in XCode

I'm working with an external code in my project which I have access to the headers and the .cc files but I don't have any access to .dylibs. I'm getting some errors, related to link of the libs, that is described bellow.
This code runs perfectly well if I run it directly from the terminal. The problem only occured when I tried to incorporate it on my own project (that have other modules) in XCode. I guess that if I add the .dylib files to XCode it will solve the problem. However, I don't have the .dylibs. How can I put this code to run?
Undefined symbols for architecture x86_64:
"FACETRACKER::IO::LoadCon(char const*)", referenced from:
mark(int, char const**) in main.o
"FACETRACKER::IO::LoadTri(char const*)", referenced from:
mark(int, char const**) in main.o
"FACETRACKER::CLM::GetViewIdx()", referenced from:
mark(int, char const**) in main.o
"FACETRACKER::FDet::~FDet()", referenced from:
FACETRACKER::Tracker::~Tracker() in main.o
FACETRACKER::Tracker::Tracker(char const*) in main.o
"FACETRACKER::Tracker::Load(char const*)", referenced from:
FACETRACKER::Tracker::Tracker(char const*) in main.o
"FACETRACKER::Tracker::Track(cv::Mat, std::__1::vector<int, std::__1::allocator<int> >&, int, int, double, double, bool)", referenced from:
mark(int, char const**) 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)

Can't compile c++ file from terminal [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 years ago.
I am using OpenCV to record the video from webcam. I used Xcode 6.4 to write a (C++) code to record the video on OS X Yosemite 10.10.4. It is working perfectly fine when I compile and run it from Xcode but when I want to compile (using g++ -o main main.cpp) it from terminal it generates following errors:
Undefined symbols for architecture x86_64:
"cv::VideoWriter::write(cv::Mat const&)", referenced from:
_main in main-027833.o
"cv::VideoWriter::VideoWriter(cv::String const&, int, double, cv::Size_<int>, bool)", referenced from:
_main in main-027833.o
"cv::VideoWriter::~VideoWriter()", referenced from:
_main in main-027833.o
"cv::VideoCapture::VideoCapture(int)", referenced from:
_main in main-027833.o
"cv::VideoCapture::~VideoCapture()", referenced from:
_main in main-027833.o
"cv::VideoCapture::operator>>(cv::Mat&)", referenced from:
_main in main-027833.o
"cv::Mat::deallocate()", referenced from:
cv::Mat::release() in main-027833.o
"cv::String::deallocate()", referenced from:
cv::String::~String() in main-027833.o
"cv::String::allocate(unsigned long)", referenced from:
cv::String::String(char const*) in main-027833.o
"cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
_main in main-027833.o
"cv::waitKey(int)", referenced from:
_main in main-027833.o
"cv::fastFree(void*)", referenced from:
cv::Mat::~Mat() in main-027833.o
"cv::VideoCapture::get(int) const", referenced from:
_main in main-027833.o
"cv::VideoCapture::isOpened() const", referenced from:
_main in main-027833.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command fail
ed with exit code 1 (use -v to see invocation)
I know its because it can't link OpenCV lib. I tried using "vi
$HOME/.bash_profile" and then setting path like
"export PATH=$PATH:/usr/local/include"
and
"export PATH=$PATH:/user/local/lib"
but it doesn't help. Also I tried
g++ -o main main.cpp -l `pkg-config opencv --cflags --libs`
but of no use.
I don't know how to specify path. Any help would be appreciated.
Thanks!
Finally, after 3 days of frustration I found the solution. I am sharing for someone who is also struggling with the same kind of problem.
What you have to do is just add all those flags that you added in the Xcode "other linker flags" while compiling your code from terminal. So here is the command that works for me.
g++ main.cpp -o main -I/usr/local/include -L/usr/local/lib -lopencv_core -lopencv_calib3d -lopencv_videoio -lopencv_video -lopencv_videostab -lopencv_highgui
I didn't include all the flags because I was only working with videos but you may have to add more or less depending on what you are working on.

Eclipse C++ for Mac settings (<iostream> fix) and error correction

I am testing out eclipse C++ for Mac. I have three specific questions.
This is the classic iostream problem for Mac. It does not know where to find it. So in the project properties I add the path where iostream is located (Preferences->C/C++ General->Paths and Symbols->includes). Now iostream works. But I am trying to find a way where I don't have to do this for every new project. Is there a specific setting I can select to include this directory automatically for each new project?
Is xCode necessary for eclipse to work? If yes, how can I get eclipse to work without it? xCode takes up 6 GBs.
I'm getting an error on a test project (see below) that I'm not sure how to fix. Something about "linker command failed". I seem to be able to compile regular C programs fine though. Note this project works fine in Visual Studio.
23:37:30 **** Incremental Build of configuration Debug for project pointClass ****
make all
Building target: pointClass
Invoking: MacOS X C++ Linker
g++ -o "pointClass" ./point.o ./test.o
Undefined symbols for architecture x86_64:
"std::istream::operator>>(double&)", referenced from:
_main in test.o
"std::ostream::operator<<(std::ostream& ()(std::ostream&))", referenced from:
_main in test.o
Point::Point(double, double) in test.o
Point::Point(Point const&) in test.o
"std::ostream::operator<<(double)", referenced from:
_main in test.o
Point::Point(double, double) in test.o
"std::basic_string, std::allocator >::~basic_string()", referenced from:
_main in test.o
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in test.o
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in test.o
"std::cin", referenced from:
_main in test.o
"std::cout", referenced from:
_main in test.o
Point::Point(double, double) in test.o
Point::Point(Point const&) in test.o
"std::basic_ostream >& std::endl >(std::basic_ostream >&)", referenced from:
_main in test.o
Point::Point(double, double) in test.o
Point::Point(Point const&) in test.o
"std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const)", referenced from:
_main in test.o
Point::Point(double, double) in test.o
Point::Point(Point const&) in test.o
"std::basic_ostream >& std::operator<<, std::allocator >(std::basic_ostream >&, std::basic_string, std::allocator > const&)", referenced from:
_main in test.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: *** [pointClass] Error 1

Poco C++ library on OSX 10.8.2: Undefined symbols for architecture x86_64

I'm trying to use Poco C++ library to do the simple http requests in C++ on Mac OS X 10.8.2. I installed Poco, copy-pasted the http_request.cc code from this tutorial, ran it with 'g++ -o http_get http_get.cc -lPocoNet', but got:
Undefined symbols for architecture x86_64:
"Poco::StreamCopier::copyStream(std::basic_istream<char, std::char_traits<char> >&, std::basic_ostream<char, std::char_traits<char> >&, unsigned long)", referenced from:
_main in ccKuZb1g.o
"Poco::URI::URI(char const*)", referenced from:
_main in ccKuZb1g.o
"Poco::URI::~URI()", referenced from:
_main in ccKuZb1g.o
"Poco::URI::getPathAndQuery() const", referenced from:
_main in ccKuZb1g.o
"Poco::URI::getPort() const", referenced from:
_main in ccKuZb1g.o
"Poco::Exception::displayText() const", referenced from:
_main in ccKuZb1g.o
"typeinfo for Poco::Exception", referenced from:
GCC_except_table1 in ccKuZb1g.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Have been struggling with this for couple of hours. Any idea how to fix this? Thanks in advance!
the Poco::URI, Poco::StreamCopier classes are in the PocoFoundation library, so you will need to link to that library also.
g++ -o http_get http_get.cc -lPocoNet -lPocoFoundation
You don't appear to have specified the include path for the library and the library to use when compiling your source.
You need to provide the -I and the -L directive to g++ to specify the include path for the library and the library itself respsectively.