Undefined reference in opencv with devc++ [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 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".

Related

C++ - Undefined reference to octomap::OcTree::OcTree(double)' [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 9 months ago.
I'm trying to use the library octomap and have installed according to the instructions in their GitHub. However, when I try to build and run this simple code with VSCode build task (with g++) I get the error: undefined reference to `octomap::OcTree::OcTree(double)' and other undefined references to Octomap related code. VSCode recognizes that the library is installed (it suggests it when I type #include <...> ) and gives me more information about the octomap functions when I hover over them.
#include <iostream>
#include <octomap/octomap.h>
#include <octomap/OcTree.h>
using namespace std;
int main()
{
octomap::OcTree tree(0.1);
cout << "Hello, World!! \n";
return 0;
}
Octomap header files are in /usr/local/lib/octomap/octomap/include/octomap from what I can tell. I haven't coded with C++ a lot, so this might be just a newbie mistake that I'm missing. I've tried several approaches but still can't get it to work. What am I missing here?
Thanks in advance.
your problem is the program wasn't linked with octomap library
use cmake and include some lines like:
find_package(octomap REQUIRED)
include_directories(${OCTOMAP_INCLUDE_DIRS})
target_link_libraries(${OCTOMAP_LIBRARIES})
or from command line with g++ <source files> -loctomap -loctomath
refer : http://wiki.ros.org/octomap

"undefined reference to `CreateStreamOnHGlobal#12'" error faced on executing gdiplus c++ code [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 1 year ago.
i found a code on github which takes a screenshot and saves it as a jpeg file. I copied and pasted it in notepad++, saved it, and compiled it with the following command:
g++ -mwindows screenshot.cpp -lgdiplus
and faced the following error:
C:\Users\USER\AppData\Local\Temp\ccTLI53G.o:screenshot.cpp:(.text+0x158): undefined reference to `CreateStreamOnHGlobal#12'
collect2.exe: error: ld returned 1 exit status
it seems to be this line which is causing the problem:
#include <stdio.h>
#include <windows.h>
#include <gdiplus.h>
#include <time.h>
//stuff....
HRESULT res = CreateStreamOnHGlobal(NULL, true, &istream);// this line (line 38)
//stuff....
Any help as to why the code is not working will be highly appreciated...
According to this site:
CreateStreamOnHGlobal function (combaseapi.h) - Win32 apps | Microsoft Docs
The library that contains CreateStreamOnHGlobal function is Ole32.lib, so -lole32 should be added to the command line.

line_descriptor.hpp is included, but KeyLine and also BinaryDescriptor are still undefined

I have been using OpenCV 3.0 that are combined with the extra modules using CMake 3.5. I am using Visual Studio 2012 32bit as my IDE.
However, i cannot seem to use both KeyLine and also BinaryDescriptor. They give me error which is "identifier KeyLine is undefined". I have set the Paths and also library setting.
#include <opencv2/opencv.hpp>
#include <opencv2/line_descriptor.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main( void ) {
Ptr<BinaryDescriptor> bd = BinaryDescriptor::createBinaryDescriptor();// this line gives error
vector<KeyLine> lines; // same as this
}
I have tried the other header, for instance the tracking.hpp. I am able to define:
Ptr<Tracker> tkr;
Without having the Tracker giving me error.
Anyone know if the error is caused during CMake process or i miss out something?
I just had the same problem, and stumbled upon your question.
The answer I just found out is you have to add,
using namespace line_descriptor;
at the top along with cv namespace.Got this hint from line_descriptor.hpp source code.

opencv undfined something wrong with my library? [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 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.

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.)