opencv 3.0.0 programming in ubuntu 14.04 - c++

I have been troubled by the problem these days. I want to write opencv-3.0.0 programs with C language in the terminal of my ubuntu 14.04 in the VM. While, in early days, I have installed Qt. Now, In order that my program is not affected by the Qt library function, I shielded the path variables of Qt in the /etc/bash.bashrc file. A simple example is as follows:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat img = imread("cornea.jpg");
imshow("src, img");
waitKey(0);
return 0;
}
Then I compile it with gcc-5.3.0 by using this command:
g++ test.cpp -o test pkg-config opencv --cflags --libs opencv
And then I have the result:
/usr/bin/ld: warning: libicui18n.so.54, needed by //home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicuuc.so.54, needed by //home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicudata.so.54, needed by //home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_clone_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘uenum_next_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘u_strToLower_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_getStandardName_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucol_setAttribute_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_setMillis_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucol_strcoll_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_setSubstChars_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_getTimeZoneDisplayName_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_openCountryTimeZones_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_fromUnicode_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_open_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_getDefaultName_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucol_open_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucol_close_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_inDaylightTime_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucol_getSortKey_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_getAvailableName_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_close_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_get_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_openTimeZoneIDEnumeration_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_getDSTSavings_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_open_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_openTimeZones_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_toUnicode_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘u_strToUpper_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘u_errorName_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_close_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘uenum_close_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_countAvailable_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_getMaxCharSize_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_getAlias_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_getDefaultTimeZone_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_compareNames_54’未定义的引用
collect2: error: ld returned 1 exit status
The backticks in command line pkg-config opencv --cflags --libs opencv is invisible.I have not got the reason now.
Why this error is related to Qt. And can you help me solve it?

Related

Affdex SDK Compilation error with undefined reference to `Visualizer::Visualizer()'

I wish to setup Affectiva SDK 4.0.0 for Linux and hence, have started working on example apps from https://github.com/Affectiva/cpp-sdk-samples
I have Ubunutu 16.04, OpenCV 2.4.11, Boost 1.63, cmake 3.8.1, pre-installed gcc 5.5.0 and manually installed gcc 5.4.0 (because I could not find a proper setup for gcc 5.4.1 as required).
When I try to run below command to compile the code from video-demo folder:
g++ video_analyse.cpp -o video_analyse -std=c++11 -I$HOME/affdex-sdk/include -L$HOME/affdex-sdk/lib -I$HOME/sdk-samples/common -l affdex-native -l boost_program_options `pkg-config opencv --cflags --libs`
The error points to below line of code:
shared_ptr<PlottingImageListener> listenPtr(new PlottingImageListener(csvFileStream, draw_display));
And receive error:
/tmp/ccWtKCG0.o: In function `PlottingImageListener::PlottingImageListener(std::basic_ofstream<char, std::char_traits<char> >&, bool)':
video_analyse.cpp:(.text._ZN21PlottingImageListenerC2ERSt14basic_ofstreamIcSt11char_traitsIcEEb[_ZN21PlottingImageListenerC5ERSt14basic_ofstreamIcSt11char_traitsIcEEb]+0x148): undefined reference to `Visualizer::Visualizer()'
collect2: error: ld returned 1 exit status
The exact same error is received with gcc 5.5.0 as well.
If I comment everything starting from that line of code, then the compilation happens successfully.
Please guide me on this. Either on how to install the exact version of gcc 5.4.1 as expected by the SDK dependency OR anything which I might be missing.

/usr/bin/ld: warning: libavcodec.so.53, needed by xxx not found

I am trying to compile a given source code with makefile, but the problem I am facing is the fact that it uses libavcodec.so.53. The version installed is 54, the libavutil and libavformat versions are also different from the Linux version. I can't change the version of them in Linux because I don't have root access. So I will use a local folder where opencv, libavutil.so, libavformat.so and libavcodec.so.53 are.
I put this folder name into the makefile.config as it follows:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /home/me/lib
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local /home/me/lib
But when I compile it I have the following errors:
/usr/bin/ld: warning: libavcodec.so.53, needed by
/home/anselmo/lib/lib/libopencv_highgui.so, not found (try using -
rpath or -rpath-link)
/usr/bin/ld: warning: libavformat.so.53, needed by
/home/me/lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libavutil.so.51, needed by
/home/me/lib/libopencv_highgui.so, not found (try using -rpath or rpath-link)
/home/anselmo/lib/lib/libopencv_highgui.so: undefined reference to
`avcodec_flush_buffers#LIBAVCODEC_53'
/home/me/lib/libopencv_highgui.so: undefined reference to
`av_freep#LIBAVUTIL_51'
/home/me/lib/libopencv_highgui.so: undefined reference to
`av_read_frame#LIBAVFORMAT_53'
libavutil.so.51, libavformat.so.53 and libavcodec.so.53 are in /home/me/lib as indicated in the makefile. How to show linux how to use them instead of the ones installed in the machine? again, I cannot be root.

How can I compile a C++ program with root library includes using g++?

I have written a C++ program (mainPixelDet1.C that uses a class defined in PixelDet1.C), that works in root's interactive mode.
But now I want to compile it outside root, using g++.
Here's what I write on the Terminal:
g++ -o main mainPixelDet1.C PixelDet1.C `root-config --cflags --glibs`
And here's what I get:
/usr/bin/ld: cannot find -lGraf3d
usr/bin/ld: cannot find -lPostscript
/usr/bin/ld: cannot find -lPhysics
collect2: error: ld returned 1 exit status
You'll have to also include --ldflags to root-config, so that root-config will supply the necessary library flag arguments.
I had the same problem and I just solved it installing these libraries: "libroot-*", "root-plugin-*","ttf-root-installer".`
I find the answer on ROOT forum if you interested, here is the link:
https://root.cern.ch/phpBB3/viewtopic.php?t=16352.
To install the library, you can write on terminal the follow command line:
sudo apt-get install nameoflibrary

error when compiling giza 1.0.5

I'm currently trying to compile GIZA++ which I downloaded from http://code.google.com/p/giza-pp/downloads/detail?name=giza-pp-v1.0.5.tar.gz. But everytime I run the make command, the following error always happened:
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lc
collect2: ld returned 1 exit status
make: *** [GIZA++] Error 1
I really don't know what is wrong, can anyone help me?
I'm using Fedora 14 with g++ version 4.5.1
Thanks for your help
The linker is saying it cannot find the C++ libraries. This suggests that there is something wrong with your GCC installation. Can you post the command line that you use to compile your code. also, can you try compiling this:
#include <iostream>
using namespace std;
int main() {
cout << "hello" << endl;
}
Save it into a file called hello.cpp, and then compile it:
g++ hello.cpp
and tell us what errors you get if any.

Linking to OpenCV under MacOSX

I'm trying to compile a C++/OpenCV Code in MacOS X Snow Leopard which was originally under Linux. I installed OpenCV 2.2 using MacPorts, but I cannot use something like this anymore:
g++ -o Localization Localization.o DataReader.o Kalman.o -libopencv_core -libopencv_highgui -L/usr/local/lib/
I'm getting this error:
ld: library not found for -libopencv_core
collect2: ld returned 1 exit status
make: *** [Localization] Error 1
I tried other variations; like -lcv, -lhighgui which I originally used to use, but I'm not sure what to use here.
If you're using macports, you're using the wrong paths. It should be -L/opt/local/lib, not /usr/local. Also, to make things easier, you should just use pkg-config:
g++ -o Localization Localization.o DataReader.o Kalman.o $(pkg-config --libs opencv)
(that assumes that you have /opt/local/bin in your PATH). This way you can use the same line for linux and OS X.
The link flag should be -lopencv_core not -libopencv_core. The latter will look for a file called libibopencv_core.{dylib,a} instead of libopencv_core.{dylib,a}. The same for opencv_highgui.