Undefined reference to `cvCreateBGCodeBookModel' - c++

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

Related

OpenCV undefined reference to `vtable for cv::HOGDescriptor'

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

FFMPEG: undefined reference to `avcodec_register_all' does not link

So I have a very sample code for trying to decode a FFMPEG video stream.
My problem is avcodec does not want to link, to do so I made a clean installation of Ubuntu 13.04. I have build ffmpeg from source following the guide here: https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu
I just want to compile my file. Note that my ubuntu does not have any implementations or header files for avcodec. The command line I use is:
gcc -I/home/USER/ffmpeg_build/include -L/home/USER/ffmpeg_build/lib -lavcodec -o test.exe Downloads/auv/src/dronerosvideo/src/ar2.cpp
/tmp/ccKTprFq.o: In function `fetch_and_decode(int, int, bool)':
ar2.cpp:(.text+0x36e):
undefined reference to `avcodec_register_all'
ar2.cpp:(.text+0x378):
undefined reference to `av_log_set_level'
ar2.cpp:(.text+0x382):
undefined reference to `avcodec_find_decoder'
ar2.cpp:(.text+0x3b1):
undefined reference to `avcodec_alloc_context3'
ar2.cpp:(.text+0x3d6):
undefined reference to `avcodec_open2'
ar2.cpp:(.text+0x46d):
undefined reference to `av_init_packet'
ar2.cpp:(.text+0x50a):
undefined reference to `avcodec_decode_video2'
ar2.cpp:(.text+0x534):
undefined reference to `av_free_packet'
/tmp/ccKTprFq.o:(.eh_frame+0x13): undefined reference to
`__gxx_personality_v0'
collect2: error: ld returned 1 exit status
Just for a sane test if I remove the -L argument compiler says:
/usr/bin/ld: cannot find -lavcodec
Which means that the linker finds the library in /home/USER/ffmpeg_build/lib. Also if we check the library for implementation it exists:
nm ffmpeg_build/lib/libavcodec.a | grep "register_all"
0000000000000000 T avcodec_register_all
Also as advised since it is C++ I have exten "C" around the include of the library.
At this point I'm falling out of any ideas at all, why exactly compilation fails?
First, it is C++, so you'll need to use g++ not gcc so that the C++ standard library gets linked. This should get rid of undefined reference to '__gxx_personality_v0'.
Then, the order of libaries to link is actually important.
You'll need to specify a library after the object (or source or other library) using it.
Putting it together, a command line like this works (in my tests):
g++ -o test.exe -I$HOME/ffmpeg/include test.cc -L$HOME/ffmpeg/lib -lavcodec
(Actually, depending on how ffmpeg was built, you might need other libraries as well, like pthreads or libx264)
If you got pkg-config installed, it might be possible to just ask that it for proper clags:
# Since you didn't install ffmpeg to a known location, tell pkg-config about that location.
export PKG_CONFIG_PATH=$HOME/ffmpeg/lib/pkgconfig
g++ -o test.exe $(pkg-config -clags libavcodec) test.cc $(pkg-config -libs libavcodec)

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

Checking Boost install with MinGW

I used the MinGW installation at http://nuwen.net/mingw.html
I ran the second.cpp test found at:
http://tabreziqbal.wordpress.com/2006/03/16/how-to-test-c-boost-installation/
(I used the correct commands to run from the comments, which was
g++ -o second second.cpp -lboost_filesystem)
I get the following error:
C:\Users\user\Projects\Programming\C++\boostTest2>g++ -o second second.cpp -lboost_filesystem
C:\Users\user\AppData\Local\Temp\ccDlbKGy.o:second.cpp:(.text+0x102): undefined reference to boost::system::generic_cat
egory()'
C:\Users\user\AppData\Local\Temp\ccDlbKGy.o:second.cpp:(.text+0x10c): undefined reference toboost::system::generic_cat
egory()'
C:\Users\user\AppData\Local\Temp\ccDlbKGy.o:second.cpp:(.text+0x116): undefined reference to boost::system::system_cate
gory()'
C:\MinGW\bin/ld.exe: C:\Users\user\AppData\Local\Temp\ccDlbKGy.o: bad reloc address 0xe in section.text$_ZN5boost6syst
em14error_categoryD1Ev[__ZN5boost6system14error_categoryD1Ev]'
C:\MinGW\bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
I know there's an installation test feature of boost that I found on
http://gcc.gnu.org/testing/testing-boost.html
but those files aren't included with the distribution from nuwen.net (so I'd have to do it myself).
And help is appreciated - I figure I'm just screwing up something minor (I hope anyway).
Thanks all!
It's not correct command, you should link boost::system too (errors are undefined references to boost::system::system_category).
Correct command will be g++ -o second second.cpp -lboost_system -lboost_filesystem

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?