OpenCV undefined reference to `vtable for cv::HOGDescriptor' - c++

I'm trying to compile my own object detector by using OpenCV 3 hog and svm over Eclipse CDT but when compiling the console returns the following:
Building target: HogDetection
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "HogDetection" ./main.o ./phog.o ./psvm.o -lopencv_core -lopencv_imgcodecs -lopencv_highgui -lopencv_ml
./phog.o: In function `cv::HOGDescriptor::HOGDescriptor()':
/usr/local/include/opencv2/objdetect.hpp:348: undefined reference to `vtable for cv::HOGDescriptor'
./phog.o: In function `cv::HOGDescriptor::~HOGDescriptor()':
/usr/local/include/opencv2/objdetect.hpp:372: undefined reference to `vtable for cv::HOGDescriptor'
collect2: error: ld returned 1 exit status
make: *** [HogDetection] Error 1
Probably I'm doing something wrong with the libraries but since I'm new both to c++ and OpenCV I followed a tutorial to set up eclipse CDT with openCV and I was able to run other simple tutorials (those on openCV websites like display image and so on...).
I also read something on wikipedia about vtable and here but it was not sufficient for me to understand what's happening here.
Thanks in advance.

I solved the problem by adding to the gcc c++ linker libraries the library opencv_objdetect

Well if you are working with make files then just add
LIBS += -L/usr/local/libs \
-lopencv_objdetect \
or if you are not having makefile then just run code like
g++ -Wall main.cpp /usr/lib/libopencv_objdetect.a -o main

Related

C++ implementing CNN Error adding symbols: DSO missing from command line

I'm testing a CNN implementation provided here. I run the command:
make cifar10 && ./cifar10
But I got the following messages:
g++ -o cifar10 BatchProducer.o ConvolutionalLayer.o ConvolutionalTriangularLayer.o IndexLearnerLayer.o MaxPoolingLayer.o MaxPoolingTriangularLayer.o NetworkArchitectures.o NetworkInNetworkLayer.o Picture.o Regions.o Rng.o SigmoidLayer.o SoftmaxClassifier.o SparseConvNet.o SparseConvNetCUDA.o SpatiallySparseBatch.o SpatiallySparseBatchInterface.o SpatiallySparseDataset.o SpatiallySparseLayer.o TerminalPoolingLayer.o cudaUtilities.o readImageToMat.o types.o utilities.o vectorCUDA.o vectorHash.o OpenCVPicture.o SpatiallySparseDatasetCIFAR10.o cifar10.o -lopencv_core -lopencv_highgui -lopencv_imgproc -lrt -larmadillo -lopenblas -lz --std=c++11 -O3
/usr/bin/ld: BatchProducer.o: undefined reference to symbol 'pthread_create##GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [cifar10] Error 1
What's wrong with this? I installed all the dependencies listed in the webpage. I did not install CUDA because I tested the CPU version here. Therefore I don't think the error is due to missing CUDA.
I'm using Ubuntu 14.04 and gcc 5.3.0.
Thank you all for helping me!!!
Solution: add '-lz' to your makefile / GCC flags. In other words, your simply missing a library in your make steps, and check if you installled all dependencies
sudo apt-get install libarmadillo-dev libopencv-core-dev libopencv-highgui-dev sparsehash

Undefined reference to `cvCreateBGCodeBookModel'

I'm getting following the error message when compiling C++ Code.
$g++ basic100.cpp -o test -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
/tmp/ccWqj7E2.o: In function `main':
basic100.cpp:(.text+0x67): undefined reference to `cvCreateBGCodeBookModel'
basic100.cpp:(.text+0x2c6): undefined reference to `cvBGCodeBookUpdate'
basic100.cpp:(.text+0x31d): undefined reference to `cvBGCodeBookClearStale'
basic100.cpp:(.text+0x374): undefined reference to `cvBGCodeBookDiff'
basic100.cpp:(.text+0x3c8): undefined reference to `cvSegmentFGMask'
collect2: error: ld returned 1 exit status
The Code worked fine in my friend's laptop.
My system is 32bit Linux Mint while they have 64bit Ubuntu 14.04.
Compilation command used in my friend's laptop
$ g++ -o fff basic100.cpp pkg-config --cflags --libs opencv
This is how I used cvCreateBGCodeBoolModel()
(model definition :CvBGCodeBookModel* model = 0;//outside main())
model = cvCreateBGCodeBookModel();
When I run the command
grep cvCreateBGCodeBookModel /usr/lib/x86_64-linux-gnu/libopencv_*.so
I get the result
Binary file /usr/lib/x86_64-linux-gnu/libopencv_legacy.so matches
So I assume you're missing the -lopencv_legacy flag in the compilation. But I have a 64 bit system.
Can you check and see if that works?
It may be that you lack some of the header files.try making the codebook structure yourself .with opencv 3.0 your code wont work since there you have to use the BackgrundSubtractorMOG class

Qt: compilation issue with minGW

I got a Qt environment that I need to compile.
But when compiling, I get the following messages:
g++ -Wl,-s -mthreads -Wl,-subsystem,windows -o release\Prog.exe object_script.Prog.Release -L"c:\DevProgs\Qt\4.8.6\lib" -lmingw32 -lqtmain build\objects\myapp_res.o -LC:/Windows/System32 -lftd2xx -LC:/qwt-6.0.1/lib -lqwt -lQtSql4 -lQtGui4 -lQtNetwork4 -lQtCore4
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x1fb): undefined reference to `_imp__Sleep#4'
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x293): undefined reference to `_imp__SetUnhandledExceptionFilter#4'
Makefile.Release:303: recipe for target 'release\Prog.exe' failed
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x2a7): undefined reference to `_set_invalid_parameter_handler'
[MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o:crtexe.c:(.text+0x475): undefined reference to `_imp__GetStartupInfoA#4'
[MGWPATH]/i686-w64-mingw32/bin/ld.exe: [MGWPATH]/i686-w64-mingw32/lib/../lib/crt2.o: bad reloc address 0x0 in section `.CRT$XCAA'
collect2.exe: error: ld returned 1 exit status
where [MGWPATH] is C:/DevProgs/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../..
I sucessfully ran small demos of Qt4.8.6 alone and one with Qwt.
The only doubt I have is regarding the ftd2xx lib.
But, I think it is linked properly because I am able to produce errors of undefined function if I don't link the DLL.
The error message is not clear to me. So, I have absolutely no idea where to look from here!
Could someone help me?
Thank you!

c++ files to include for boost : asio

I'm following this tutorial however it does not state which libaries I need to include in order to get boost to work,current options for links are:
-I/usr/include/opencv2 -I/usr/include/boost_1_55_0 -I/usr/include/boost_1_55_0/boost -O0 -g3 -Wall -c -fmessage-length=0
however this returns the following erro:
which states that it can't find asio, am I doing something wrong or was assio the wrong library to link to? Or is there any other way to find out. Note that this is my 2nd c++ project(through I have a lot of java experience) and first with the heavy use of libraries so details are somewhat required.
Removing boost/asio gave me the following errors:
make all
Building target: DisplayImage
Invoking: GCC C++ Linker
g++ -L/usr/include/opencv2 -L/usr/include/boost_1_55_0/boost -L/usr/include/boost_1_55_0 -L/usr/include/opencv2 -L/usr/lib -o "DisplayImage" ./src/Cap.o ./src/DisplayImage.o ./src/Filters.o ./src/sender.o -lopencv_imgproc -lopencv_highgui -lopencv_core
./src/sender.o: In function `__static_initialization_and_destruction_0':
/usr/include/boost_1_55_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
/usr/include/boost_1_55_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
/usr/include/boost_1_55_0/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
./src/sender.o: In function `error_code':
/usr/include/boost_1_55_0/boost/system/error_code.hpp:323: undefined reference to `boost::system::system_category()'
./src/sender.o: In function `boost::asio::error::get_system_category()':
/usr/include/boost_1_55_0/boost/asio/error.hpp:224: undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [DisplayImage] Error 1
Build Finished **
I use an ubuntu (x64) laptop if it matters.
Most of boost is implemented in what's called "header-only" code. Through the generous use of C++ templates, there is no actual library code to which your code needs to link. However, there are, as you've seen some actual libraries as well. Generally, the help you seek is probably here: http://www.boost.org/doc/libs/1_55_0/more/getting_started/unix-variants.html#link-your-program-to-a-boost-library
Your particular program uses the timer and system libraries and so you can probably use this command line to link your program:
g++ timer.cpp -o timer -lboost_timer -lboost_system
You can look at the bjam in boost/libs/asio/example/cpp03/tutorial/Jamfile.v2:
project
: requirements
<library>/boost/system//boost_system
<library>/boost/thread//boost_thread
<define>BOOST_ALL_NO_LIB=1
<threading>multi
<os>SOLARIS:<library>socket
<os>SOLARIS:<library>nsl
<os>NT:<define>_WIN32_WINNT=0x0501
<os>NT,<toolset>gcc:<library>ws2_32
<os>NT,<toolset>gcc:<library>mswsock
<os>NT,<toolset>gcc-cygwin:<define>__USE_W32_SOCKETS
<os>HPUX,<toolset>gcc:<define>_XOPEN_SOURCE_EXTENDED
<os>HPUX:<library>ipv6
;
You can see that they build all the tutorial steps with
-lboost_system -lboost_thread -DBOOST_ALL_NO_LIB=1
on linux

Compile C++ and OpenSSL on Ubuntu 11.10

I got a serious problem compiling my C++ and OpenSSL project on my Ubuntu 11.10.
The compiling command is:
g++ -Wall -lssl -lm -lcrypto -I ./src ./src/server.cpp -o ./bin/server
I receive these errors:
server.cpp:(.text+0x8ff): undefined reference to `RSA_new'
server.cpp:(.text+0x92d): undefined reference to `PEM_read_RSAPrivateKey'
server.cpp:(.text+0xa85): undefined reference to `RSA_size'
server.cpp:(.text+0xaa1): undefined reference to `RSA_size'
server.cpp:(.text+0xae7): undefined reference to `RSA_private_decrypt'
server.cpp:(.text+0xd84): undefined reference to `BF_set_key'
server.cpp:(.text+0xf1d): undefined reference to `BF_ecb_encrypt'
server.cpp:(.text+0x13c6): undefined reference to `BF_ecb_encrypt'
collect2: ld returned 1 exit status
make: *** [server] Error 1
I successfully installed openssl and libssl-dev but the problem persists.
I tried to compile the project on Linux Mint 12 with the kernel 3.0 and I had the same problem.
On my old Linux OS with the kernel 2.6 the project compiled and worked fine (using the same Makefile and the same sources).
Please help me!
Generally you need to have the -l link flags after the code that references them. Try
g++ -Wall -I ./src ./src/server.cpp -o ./bin/server -lssl -lm -lcrypto
As the comment to this answer states, the linker only looks for undefined symbols to include in the order the parameters are listed.
That is, if your cpp file uses the libraries, the libraries have to be listed after the cpp file.
Those error are from crypto library, check whether ssl and crypto libraries are available in /usr/lib or where ever u installed if not install them and have u set the library search path for libssl and libcrypto in your compiling command?