opencv undfined something wrong with my library? [duplicate] - c++

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I have installed opencv using the following commands:
git clone https://github.com/jayrambhia/Install-OpenCV.git
cd Install-OpenCV/
./dependencies.sh
./opencv_latest.sh
this gave me the following message:
Package ffmpeg is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
Deciding that this may or may not matter I went on into codeblock and created a default opencv template project.
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
Mat img = imread("lena.jpg", CV_LOAD_IMAGE_COLOR);
if(img.empty())
return -1;
namedWindow( "lena", CV_WINDOW_AUTOSIZE );
imshow("lena", img);
waitKey(0);
return 0;
}
This showed no errors but on compile gave me the following errors:
AR: 9 undfined reference to 'cv::imread(std::string const&,int)'
AR: 12 undfined reference to 'cv::na(std::string const&,int)'
AR: 13 undfined reference to 'cv::InputArray::_InputArray(cv::Mat const&)'
AR: 13 undfined reference to 'cv::imshow(std::string const&, cv::InputArray(const&)'
AR: 14 undfined reference to 'cv::waitKey(int)'
usr/include/opencv... 278 undfined reference to 'cv::fastFree(void*)'
usr/include/opencv... 367 undfined reference to 'cv::Mat::deallocate()'
running the getlatest under sudo instead gave me the following exchange:
sudo ./opencv_latest.sh
... some normal looking stuff...
./opencv_latest.sh: 7: ./opencv_install.sh: [[: not found
./opencv_latest.sh: 11: ./opencv_install.sh: [[: not found
./opencv_latest.sh: 15: ./opencv_install.sh: [[: not found
--- Installing OpenCV 2.4.9
--- Installing Dependencies
./opencv_latest.sh: 27: ./opencv_install.sh: source: not found
Attempting to do what they did here: http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation
gave me the following result:
Prg1#KILLBOX:/usr/include/opencv2/release$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/include/opencv2
CMake Error: The source directory "/usr/include/opencv2/release/CMAKE_INSTALL_PREFIX=/usr/include/opencv2" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
Here are picks of my linker and compiler settings:
So anybody know what I'm doing wrong this is on ubuntu 14.04 LTS and codeblocks
edit:
using ldconfig -p | grep opencv
gave me a mountain of opencv files that should mean it's installed right, right? So it the problem with the linker and compiler? Note that linker settings in the compiler settings (not the search directories) show the opencv libs as being empty so which one is it?
By the way clicking on the error messages in codeblocks (the once inside the opencv lib) does in fact bring up pieces of the opencv lib which look like the proper lines of code to be at that position (as in they contain functions that the log shows as missing)

Did you build your OpenCv properly after downloading it's source from git.
Check out this link :- http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html
Underfined reference error means that the linker is unable to find the code for the functions you are using in your project, as a result you need to first install opencv properly.

Related

dyld: Symbol not found: _PyBaseObject_Type

I'd like to use the Boost library in my C++ code, so I've inputted the right include search path and the right library search path, then I added all the Boost library files in Xcode. When I build my code the compiler says that the build is successful. However, once I run the code, the console tells this:
Console:
dyld: Symbol not found: _PyBaseObject_Type
Referenced from: /usr/local/lib/libboost_python27.dylib
Expected in: flat namespace
in /usr/local/lib/libboost_python27.dylib
Program ended with exit code: 9
My code:
#include <iostream>
#include <boost/any.hpp>
int main()
{
std::cout << std::endl;
return 0;
}
Where is my mistake? Please help.
This error occurs when you don't add a package to your project the right way. The problem has resolved in my example by installing Boost via Homebrew. Installing the package the right way means that if you install it manually (e.g. downloading it from GitHub), you should install it on the right path. But I suggest always installing C++ packages via Homebrew.

Undefined reference in opencv with devc++ [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 6 years ago.
I was trying to install opencv with devc++ on my windows system. I installed opencv and then added a new compiler in devc++.
I added the following command in calling the new compiler section
-L"C:\OpenCV\lib" -lcxcore210 -lcv210 -lcvaux210 -lhighgui210 -lml210
I added the follwing command for linker command line
-lcxcore210 -lcv210 -lcvaux210 -lhighgui210 -lml210
I added the corresponding opencv binaries,libraries and includes too and added opencv/bin to environment variables.
However when i try to run follwing opencv code,
#include <iostream>
#include <conio.h>
using namespace std;
#include "cv.h"
#include "highgui.h"
using namespace cv;
int main()
{
cv::Mat img;
getch();
}
It gives the following error.
[Linker error]
C:\Users\user\AppData\Local\Temp\ccGQvgqG.o:filename.cpp:(.text$_ZN2cv3Mat7releaseEv[cv::Mat::release()]+0x3f):
undefined reference to `cv::fastFree(void*)'
Please, do not use OpenCV 2.1.0.
Use OpenCV 2.4.13 or 3+.
As you can read in the documentation:
Prebuilt libraries [...] only works if you are coding with the latest Microsoft Visual Studio IDE.
If you want to use other compiler than Visual C++, you must build OpenCV libraries yourself. A good start is this tutorial. Take care, because they are "long-obsolete and contain inaccurate information".

c++ openCV 3.1 - can't use Mat or most of the openCV things like in the tutorials

Best
I'm trying to create a project in C++, which relays most of the time on the
open-cv library.
Therefore, I've installed open-cv3.1.0 on my windows machine and connected the
library and include map/files to my netbeans c++ project.
Succes
Overall I think that I've managed to do this correctly because
I don't receive any errors when I compile/run the application with the next piece of code in it.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
++ I can read an images in and visualize it :)
CvMat *img = cvLoadImageM(location.c_str(),CV_LOAD_IMAGE_GRAYSCALE);
cvNamedWindow( "My Window", 1 );
cvShowImage( "My Window", img );
cvWaitKey();
Problem
But as soon as I take a random tutorial. E.g.
// create a big 8Mb matrix
Mat A(1000, 1000, CV_64F);
http://docs.opencv.org/3.0-last-rst/modules/core/doc/intro.html
Or even
Mat A;
Then I get immediately an compile error :
g++ -o dist/Debug/Cygwin-Windows/ai4 build/Debug/Cygwin-Windows/PrincipalComponentAnalysis.o build/Debug/Cygwin-Windows/ReadInImage.o build/Debug/Cygwin-Windows/main.o -L../../../netbeans/OpenCV/opencv/build/x64/vc14/bin -lopencv_world310 -lopencv_world310d
build/Debug/Cygwin-Windows/PrincipalComponentAnalysis.o: In function `cv::Mat::~Mat()':
/cygdrive/d/fun/ai/ai4/../../../netbeans/OpenCV/opencv/build/include/opencv2/core/mat.inl.hpp:571: undefined reference to `cv::fastFree(void*)'
...
The only things which doesn't give me an error are :
CvMat A;
CvMat *B;
IplImage *C;
IplImage D;
Which s***t because most (all) the tutorials, and stackoverflow issues are using the Mat A or cv::Mat A version.
Question
Thus the question : Did you've ever had the same kind of problem or issue? and are you willing to help me? + How can I solve it.
edit : Configuration steps - OpenCV 3.1
Tools --> Options --> c/c++ --> Code Assistance :
D:\netbeans\openCV\opencv\build\include
D:\netbeans\openCV\opencv\build\include\opencv2
R-click Project --> Properties --> build --> C++ Compiler --> include directories
../../../netbeans/OpenCV/opencv/build/include
../../../netbeans/OpenCV/opencv/build/include/opencv2
R-click Project --> Properties --> build --> linker --> Additional Library Directories
../../../netbeans/OpenCV/opencv/build/x64/vc14/bin
R-click Project --> Properties --> build --> linker --> Libraries --> Add Labrary
opencv_world310
opencv_world310d
Solution
Download CMake
Download OpenCV
Download MinGW <-- Use this as compiler instead of cygwin
Install MinGW
Follow this link --> http://eyalarubas.com/opencv-installation-on-windows-netbeans-mingw.html
you are compiling with cygwin and linking to the VC14 libs.
That's your error. VC14 is for MSVC14 (Visual Studio Compiler), you will need to compile OpenCV yourself to use cygwin. OpenCV does not come with other pre-built libraries.
There are multiple tutorials online of how to do it but effectively you need to use cmake in order to compile OpenCV for your particular tool chain.
You have problem while calling the destructor of cv::Mat. I faced this problem onced. It was related to mismatch between the library and the program. For example 64 and 32 ,debug and release or mt and md something like these. So, the first thing that you have to do is to make sure that everything are matched between OpenCV built and your calling program.

linking jsoncpp on Ubuntu

I try to use jsoncpp library with c++ on Ubuntu.
I compiled the code and built the library with scons.
Now I can compile a simple programme:
#include "json/json.h"
#include <json/value.h>
#include <json/writer.h>
int main()
{
return 0;
}
I use this command to compile:
g++ test.cpp -usr/lib/libjson_linux-gcc-4.8_libmt
I conclude that the compiler knows where to find the library.
The problem comes when I declare a json object:
Json::Value root;
Then I have this error message:
undefined reference to « Json::Value::Value(Json::ValueType) »
How can I fix this problem?
For CodeBlocks (Ubuntu 14.04)
I have faced same problem in my codeblocks IDE after installing jsconcpp. This is how I rectified my problem.
Got to project>Build Options>linker settings and in the link libraries add jsconcpp and click ok

Type undefined reference to `cv::fastFree(void*)'

I started the tutorial for opencv 2.4.7 on Win8, latest MinGW, and Eclipse Kepler R1, CDT. C++ Compiler includes are referencing to [path-to-opencv]\open247\build\include.
in the MinGW C++ Linker I add the library path [path-to-opencv]\open247\build\x64\vc11\lib. The vc11 directory contains libraries for VisualStudio from what I've read. Is that still okay to compile them with MinGW?
I added the core and highgui library for this sample (I don't think we need more than those).
However, for this simple idle code below, I provoke the following compilation error.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main(){
Mat image;
}
The error on compilation is:
Description Resource Path Location Type
undefined reference to `cv::fastFree(void*)' FirstOpenCV line 278, external location: C:\Users\John\Documents\Software\opencv247\build\include\opencv2\core\mat.hpp C/C++ Problem
What's the reason for this?
If I add
namedWindow("testWindow", 1);
I even get this error
Description Resource Path Location Type
undefined reference to `cv::namedWindow(std::string const&, int)' main.cpp /FirstOpenCV/src line 23 C/C++ Problem
Have you link correctly your library?
-lopencv_core
-lopencv_highgui
-L<opencv_library_path>
The libraries have to be specified after the source file on the compiler/linker command line. (The linker keeps track of unresolved symbols, and resolves them via later command-line arguments.)