I'm bundling openCV into an SDK for people developing in C++ in linux. I'm linking a test executable with my built library and its giving me a huge dump of errors, one of which is:
/path/to/build/libopencv_core.a(copy.cpp.o): In function `cv::Mat::setTo(cv::_InputArray const&, cv::_InputArray const&)':
copy.cpp:(.text._ZN2cv3Mat5setToERKNS_11_InputArrayES3_+0x15c1): undefined reference to `ippicviSet_32f_C1MR'
copy.cpp:(.text._ZN2cv3Mat5setToERKNS_11_InputArrayES3_+0x1700): undefined reference to `ippicviSet_32f_C4MR'
copy.cpp:(.text._ZN2cv3Mat5setToERKNS_11_InputArrayES3_+0x1743): undefined reference to `ippicviSet_32s_C4MR'
copy.cpp:(.text._ZN2cv3Mat5setToERKNS_11_InputArrayES3_+0x17a4): undefined reference to `ippicviSet_16s_C4MR'
copy.cpp:(.text._ZN2cv3Mat5setToERKNS_11_InputArrayES3_+0x1805): undefined reference to `ippicviSet_16u_C4MR'
What is this error referencing? Should I be building without ipp? I compiled the opencv libs -fPIC and standalone. I'm actually getting thousands of errors which have some mention of ippicvi and this is just an example.
I had the same error. You need to link the executable to the library libippicv.
This is a 3rd party library used by OpenCV an you can find it in /usr/local/share/OpenCV/3rdparty/lib/libippicv.a.
You can also find in opencv.pc all the dependencies used by OpenCV. E.g.:
/usr/local/lib/pkgconfig/opencv.pc
# Package Information for pkg-config
prefix=/usr/local exec_prefix=${prefix} libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 3.2.0
Libs: -L${exec_prefix}/lib -lopencv_shape -lopencv_stitching
-lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
Libs.private: -L${exec_prefix}/share/OpenCV/3rdparty/lib -llibwebp
-lippicv -L/usr/lib/x86_64-linux-gnu -lpng -lz -ltiff -ljasper -ljpeg -lImath -lIlmImf -lIex -lHalf -lIlmThread -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lgthread-2.0 -ldc1394 -lavcodec-ffmpeg -lavformat-ffmpeg -lavutil-ffmpeg -lswscale-ffmpeg -lstdc++ -ldl -lm -lpthread -lrt Cflags: -I${includedir_old} -I${includedir_new}
Related
I have installed opencv2.
pkg-config --modversion opencv
2.4.13.5
I am using below code,
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, const char *argv[])
{
VideoCapture vid(0);
if(!vid.isOpened()){
cout<<"Camera could not load..."<<endl;
return -1;
}
namedWindow("webcam",CV_WINDOW_AUTOSIZE);
while(1){
Mat frame;
bool ctrl = vid.read(frame);
imshow("webcam",frame);
if(waitKey(0) == 27){
cout<<"The app is ended..."<<endl;
break;
}
}
return 0;
}
I compiled using, g++ image_writer.cpp
/tmp/ccPWmgA0.o: In function main':
image_writer.cpp:(.text+0x38): undefined reference tocv::VideoCapture::VideoCapture(int)'
image_writer.cpp:(.text+0x47): undefined reference to cv::VideoCapture::isOpened() const'
image_writer.cpp:(.text+0xac): undefined reference tocv::namedWindow(std::__cxx11::basic_string, std::allocator > const&, int)'
image_writer.cpp:(.text+0xe9): undefined reference to cv::VideoCapture::read(cv::Mat&)'
image_writer.cpp:(.text+0x105): undefined reference tocv::_InputArray::_InputArray(cv::Mat const&)'
image_writer.cpp:(.text+0x148): undefined reference to cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
image_writer.cpp:(.text+0x170): undefined reference tocv::waitKey(int)'
image_writer.cpp:(.text+0x1cd): undefined reference to cv::VideoCapture::~VideoCapture()'
image_writer.cpp:(.text+0x254): undefined reference tocv::VideoCapture::~VideoCapture()'
/tmp/ccPWmgA0.o: In function cv::Mat::~Mat()':
image_writer.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference tocv::fastFree(void*)'
/tmp/ccPWmgA0.o: In function cv::Mat::release()':
image_writer.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference tocv::Mat::deallocate()'
collect2: error: ld returned 1 exit status
After surfing I found, I have to include lib file
so, I did this. g++ image_writer.cpp -lopencv_videoio
/usr/bin/ld: cannot find -lopencv_videoio
collect2: error: ld returned 1 exit status
I don't know how to fix this. please help me how to fix this. Any hint would be appreciable.
EDIT-1:
pkg-config --libs opencv returns,
-L/usr/local/lib -lopencv_contrib -lopencv_stitching -lopencv_nonfree -lopencv_superres -lopencv_ocl -lopencv_ts -lopencv_videostab -lopencv_gpu -lopencv_photo -lopencv_objdetect -lopencv_legacy -lopencv_video -lopencv_ml -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_imgproc -lopencv_flann -lopencv_core -lQtCore -lQtTest -lQtGui -lQtOpenGL -lIlmThread -lHalf -lIex -lIlmImf -lImath -ljasper -ltiff -lpng -ljpeg -lswscale-ffmpeg -lavutil-ffmpeg -lavformat-ffmpeg -lavcodec-ffmpeg -lv4l2 -lv4l1 -ldc1394 -lgstpbutils-0.10 -lgstriff-0.10 -lgstapp-0.10 -lgstvideo-0.10 -lxml2 -lglib-2.0 -lgthread-2.0 -lgmodule-2.0 -lgobject-2.0 -lgstreamer-0.10 -lgstbase-0.10 -lGLU -lGL -lz -latomic -ltbb -lrt -lpthread -lm -ldl -lstdc++
The OpenCV "library" is really a collection of multiple libraries, and you usually need to link with multiple libraries.
The simple solution is to use pkg-config --libs opencv to get all linker flags and libraries that are needed:
g++ image_writer.cpp `pkg-config --libs opencv`
compilation using cmake
cmake_minimum_required(VERSION 2.8)
project(ImageWriter)
add_executable(${PROJECT_NAME} "image_writer.cpp")
FIND_PACKAGE(OpenCV REQUIRED )
include_directories(${OPENCV_INCLUDE_DIRS})
message(" cv_libs: " ${OpenCV_LIBS})
message(" cv_includes: " ${OPENCV_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OpenCV_LIBS})
I am trying to build a sample from OpenCV. Unfortunately I always get these errors while building.
I made an installation with opencv_contrib. OpenCV is installed in ~/lib/pokus/installed (contains bin include lib share). I am buiding example ~/lib/pokus/installed/share/OpenCV/samples/cpp/opencv_version.cpp (which came with OpenCV).
My g++ command:
g++ $(pkg-config --cflags --libs ~/lib/pokus/installed/lib/pkgconfig/opencv.pc) opencv_version.cpp -o test
Result:
opencv_version.cpp:(.text+0x78): undefined reference to `cv::CommandLineParser::CommandLineParser(int, char const* const*, cv::String const&)'
opencv_version.cpp:(.text+0xa8): undefined reference to `cv::CommandLineParser::has(cv::String const&) const'
opencv_version.cpp:(.text+0xc6): undefined reference to `cv::CommandLineParser::printMessage() const'
opencv_version.cpp:(.text+0xd7): undefined reference to `cv::CommandLineParser::check() const'
opencv_version.cpp:(.text+0xea): undefined reference to `cv::CommandLineParser::printErrors() const'
opencv_version.cpp:(.text+0x113): undefined reference to `cv::CommandLineParser::has(cv::String const&) const'
opencv_version.cpp:(.text+0x12a): undefined reference to `cv::getBuildInformation()'
opencv_version.cpp:(.text+0x180): undefined reference to `cv::CommandLineParser::~CommandLineParser()'
opencv_version.cpp:(.text+0x1bc): undefined reference to `cv::CommandLineParser::~CommandLineParser()'
opencv_version.cpp:(.text+0x1f8): undefined reference to `cv::CommandLineParser::~CommandLineParser()'
/tmp/ccRHDRg5.o: In function `cv::String::String(char const*)':
opencv_version.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccRHDRg5.o: In function `cv::String::~String()':
opencv_version.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
Content of ~/lib/pokus/installed/lib/pkgconfig/opencv.pc
# Package Information for pkg-config
prefix=~/lib/pokus/installed
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 3.2.0
Libs: -L${exec_prefix}/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cvv -lopencv_dpm -lopencv_freetype -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_plot -lopencv_dnn -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core
Libs.private: -L/usr/lib/x86_64-linux-gnu -lQt5Test -lQt5Concurrent -lQt5OpenGL -lpng -lz -ltiff -ljasper -ljpeg -lImath -lIlmImf -lIex -lHalf -lIlmThread -ldc1394 -lavcodec-ffmpeg -lavformat-ffmpeg -lavutil-ffmpeg -lswscale-ffmpeg -lQt5Core -lQt5Gui -lQt5Widgets -ldl -lm -lpthread -lrt -lGLU -lGL -ltbb
Cflags: -I${includedir_old} -I${includedir_new}
Sorry for so frequently asked question, but none of the others seems to solve my problem.
Thanks for all tips!
The file name must come before the params:
g++ opencv_version.cpp $(pkg-config --cflags --libs ~/lib/pokus/installed/lib/pkgconfig/opencv.pc) -o test
I had the same issue trying to work with OPENCV 4.3.0 after installation and so. In order to add the libs and compile properly.
Worked for me in order to test the opencv_version.cpp
g++ opencv_version.cpp $(pkg-config --cflags --libs opencv4) -o opencv_version
Result
./opencv_version
Welcome to OpenCV 4.3.0
I am new to C++, openCV and Artoolkit
I am trying to build a motion tracker devices
right now, I am following the tutorial
https://artoolkit.org/blog/2016/05/opencv-with-artoolkit
However I meet some problem when I trying to implement this on SimpleTest on the Linux machine.
The error I get is like this:
"clang++ -c -O3 -fPIC -march=core2 -DHAVE_NFT=1 -I/usr/include/x86_64-linux-gnu -pthread -I/usr/include/gstreamer-0.10 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libxml2 -I../../include simpleTest.c
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated In file included from simpleTest.c:79: In file included from ../../include/linux-x86_64/opencv2/opencv.hpp:59:/usr/include/opencv2/contrib/contrib.hpp:273:23: error: no template named
'vector'; did you mean 'std::vector'?"
simpleTest code
I added line like this
#include <linux-x86_64/opencv2/opencv.hpp>
#include <linux-x86_64/opencv2/opencv_modules.hpp>
using namespace std;
using namespace cv;
in the make file:
I add some this:
LIBS= -lARgsub -lARvideo -lAR -lARICP -lAR -lglut -lGLU -lGL -lX11 -lm -lpthread -ljpeg -pthread -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lxml2 -lglib-2.0 -ldc1394 -lraw1394 -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_viz -lippicv -lopencv_core
and
CC = clang++
There are some similar issues found on SO here.....
Linking C from C++ in OS X Mavericks
Warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated
There's a mismatch between C++ and C.
To get around this, it would be best if you used ARWrapper for ARToolkit within a C++ framework.
I would like to compile a C++ program that uses openCV statically, so that I can use it on other computers without having to install openCV.
I compiled openCV 2.4.5 with following flags in order to get static libraries and to install it besides my main installation which is version 3.1.
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/opt/openCV_2_4_5 -D WITH_FFMPEG=OFF -DBUILD_SHARED_LIBS=NO ..
ls /opt/openCV_2_4_5/lib
libopencv_calib3d.a libopencv_flann.a libopencv_legacy.a libopencv_photo.a libopencv_video.a
libopencv_contrib.a libopencv_gpu.a libopencv_ml.a libopencv_stitching.a libopencv_videostab.a
libopencv_core.a libopencv_highgui.a libopencv_nonfree.a libopencv_superres.a pkgconfig
libopencv_features2d.a libopencv_imgproc.a libopencv_objdetect.a libopencv_ts.a python2.7
After installing, I tried to compile a c++ program for face detection like this:
g++ -std=c++11 -L/opt/openCV_2_4_5/lib -I/opt/openCV_2_4_5/include -o ex2 ex2.cpp -L. -lpthread -lz -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core
From that I got the error:
/tmp/cct4prBn.o: In function `main':
ex2.cpp:(.text+0x141): undefined reference to `cv::imread(std::string const&, int)'
ex2.cpp:(.text+0x2bc): undefined reference to `cv::imread(std::string const&, int)'
ex2.cpp:(.text+0x4f3): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
collect2: error: ld returned 1 exit status
make_2_4_5:9: recipe for target 'ex2' failed
make: *** [ex2] Error 1
I used the same library flags as my installation of OpenCV 3.1 has. I got them from:
pkg-config --cflags --libs opencv
The -L and -I flags point to the openCV 2.4.5 installation in the /opt directory.
Why doesn't it compile? All OpenCV libraries are listed in the section where the static libraries should be.
In OpenCV 2 I believe cv::imread() and cv::imwrite() are in the highgui library. In OpenCV 3 they were moved to the imgcodecs library. Try adding:
-lopencv_highgui
to your command line.
I'm trying to complie opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp through:
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary surf_keypoint_matcher.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_stitching -lopencv_imgcodecs -lopencv_xfeatures2d
But I'm getting this error:
/tmp/ccQW7t3Z.o: In function `main':
/home/luca/Downloads/opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp:65: undefined reference to `cv::cuda::DescriptorMatcher::createBFMatcher(int)'
collect2: error: ld returned 1 exit status
Why?
Your error message:
/home/luca/Downloads/opencv-3.1.0/samples/gpu/surf_keypoint_matcher.cpp:65: undefined reference to `cv::cuda::DescriptorMatcher::createBFMatcher(int)'
collect2: error: ld returned 1 exit status
shows that you have an undefined reference to cv::cuda::DescriptorMatcher::createBFMatcher
this resides in the cuda libs so you need to include the appropriate headers and link into the following libs as opencv_cudafeatures2d depends on them:
opencv_cudafilters
opencv_cudawarping
opencv_features2d
opencv_cudaarithmn
opencv_flann
opencv_core
certainly this is true for opencv version 3.1.0 which is what I'm using
DescriptorMatcher is in cudafeatures2d.hpp. So, you have to include the header cudafeatures2d.hpp in the .cpp program and link the library in the compile process.
The program runs if you use this -lopencv_cudafeatures2d:
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib/ -g -o binary surf_gpu_probe1.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_stitching -lopencv_imgcodecs -lopencv_xfeatures2d -lopencv_cudafeatures2d