OpenCV4 on XCode — opencv2/core.hpp not found - c++

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?

Related

clang++ linker undefined symbols for architecture x86_64

$clang++ main.cpp -o out
Got following error, the same error happens when changing to g++. I have tested on some simple simple c++ code, the command works fine. So it the problem in that PNG class file? However, the same files worked on my MacOS before, but suddenly failed today.
Undefined symbols for architecture x86_64:
"PNG::writeToFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in main-f6a06a.o
"PNG::PNG(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
_main in main-f6a06a.o
"PNG::PNG(unsigned long, unsigned long)", referenced from:
_main in main-f6a06a.o
"PNG::~PNG()", referenced from:
_main in main-f6a06a.o
"PNG::operator()(unsigned long, unsigned long)", referenced from:
_main in main-f6a06a.o
"PNG::width() const", referenced from:
_main in main-f6a06a.o
"PNG::height() const", referenced from:
_main in main-f6a06a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Did you miss providing static/shared to the linker to resolve the linker errors for the methods mentioned? Also note that clang++ is a different compiler compared to g++ and hence need the static/shared libraries compiled prior by the same compiler you are using (clang++).
Try:
clang++ main.cpp -o out -lpng
Here's why: You are not providing the library that contains the implementation of your PNG library (libpng most likely). You need -lpng added to your compiler, so that it links with the relevant library. It may not be exactly -lpng in your particular case, but it's definitely a "missing library". Without knowing exactly what library you are trying to use (you didn't provide some source to "try the fix with").
As pointed out in the comment: you are using some kind of C++ wrapper on top, the above is probably not enough - but without knowing exactly which C++ wrapper on the png functionality you are actually using, it's hard to say what the command-line should look like.
Perhaps this

Error locating libraries when using gmp

So I have been writing a c++ program and in it it handles integers too large for the inbuilt long long. No problem, I'll just use a bignum library. So I get GMP, utter those three magic commands "./configure, make, make install" and start using it. I use #include "gmpxx.h" as specified in the docs for a c++ program. Compiling it, GPP finds an error in gmpxx.h as apparently gmp.h can't be located using angles and quotes should be used instead in the include statement in gmpxx.h. Upon changing the angles to quotes, however, I am surprised to discover that something has gone wrong, I think with 'make'. It says:
Undefined symbols for architecture x86_64:
"___gmpz_clear", referenced from:
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr() in primality-3fd487.o
"___gmpz_cmp_si", referenced from:
__gmp_binary_equal::eval(__mpz_struct const*, long) in primality-3fd487.o
"___gmpz_init", referenced from:
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr() in primality-3fd487.o
"___gmpz_set_d", referenced from:
__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::assign_d(double) in primality-3fd487.o
"___gmpz_tdiv_r_ui", referenced from:
__gmp_binary_modulus::eval(__mpz_struct*, __mpz_struct const*, long) in primality-3fd487.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does anyone know how to stop either of these errors occurring?

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.

Xcode 6.3 Apple Match-O linker Error with cocos2d v2.1.5 project

I got a problem when I rebuild cocos2d v2.1.5 with architecture x64 in xcode 6.3. please help me fix this.
Undefined symbols for architecture arm64:
"_WebPGetFeaturesInternal", referenced from:
WebPGetFeatures(unsigned char const*, unsigned long, WebPBitstreamFeatures*) in CCImageCommonWebp.o
"_WebPInitDecoderConfigInternal", referenced from:
WebPInitDecoderConfig(WebPDecoderConfig*) in CCImageCommonWebp.o
"_WebPDecode", referenced from:
cocos2d::CCImage::_initWithWebpData(void*, int) in CCImageCommonWebp.o
"_NEON_Matrix4Mul", referenced from:
_kmMat4Multiply in mat4.o
"_AES_decrypt", referenced from:
DataEncrypt::parseXMLData(unsigned long, char const*) in UserDataEncrypt.o
"_AES_set_encrypt_key", referenced from:
DataEncrypt::save() in UserDataEncrypt.o
"_AES_encrypt", referenced from:
DataEncrypt::save() in UserDataEncrypt.o
"_AES_set_decrypt_key", referenced from:
DataEncrypt::parseXMLData(unsigned long, char const*) in UserDataEncrypt.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You have to update cocos2d to version 2.2.6. It's minimum version which supports x64 architecture. However it's not stable, so you'd better update to 3.6 if you have enough time.
Link to tutorial
We've started migration and it looks like it will take 80+ hours because of big changes in API.

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.