I am getting the following errors:
//usr/local/lib/libsmfitting.so: undefined reference to `VO_FaceParts::VO_GetOneFacePart(unsigned int) const'
//usr/local/lib/libsmfitting.so: undefined reference to `cv::estimateRigidTransform(cv::_InputArray const&, cv::_InputArray const&, bool)'
collect2: error: ld returned 1 exit status
Being produced from this makefile:
Cxx=g++
CXXFLAGS = -I/usr/local/include/opencv -I/usr/local/include/opencv2 -I/usr/local/include/vosm/smfitting -I/usr/local/include/vosm/smbuilding -I/usr/local/include/vosm/comalgs -I/usr/local/include/vosm/cvcommon -I/usr/local/include/vosm/ensembletraining -I/usr/local/include/vosm/featureextraction -I/usr/local/include/vosm/integraltransform -I/usr/local/include/vosm/utils
LIBS = -lopencv_ml -lopencv_calib3d -lopencv_legacy -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_video -lopencv_objdetect -lcomalgs -lcvcommon -lensembletraining -lfeatureextraction -lintegraltransform -lsmbuilding -lutils -lboost_system -lboost_filesystem -lsmfitting
all: faceApp.cpp
$(Cxx) -o faceApp faceApp.cpp $(CXXFLAGS) $(LIBS)
The code appears to be correct and the libraries appear to be built correctly, I believe the error lies in the makefile.
The order of the libraries when linking is significant, and should be in reverse dependency order. So if library B depends on library A, then you need to put B before A when linking.
In your case it seems that the smfitting library depends on one of the OpenCV libraries, as well as some other library, so you need to put it before those libraries.
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 currently trying to build and run the kalman filter example program found on https://docs.opencv.org/trunk/de/d70/samples_2cpp_2kalman_8cpp-example.html#a12
When I try to compile the program, I get the following output:
g++ -o kalman kalman.o -lopencv_core -lopencv_tracking -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio -lopencv_objdetect
/usr/bin/ld: kalman.o: undefined reference to symbol '_ZN2cv12KalmanFilter7predictERKNS_3MatE'
/usr/bin/ld: /usr/lib/libopencv_video.so.4.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: kalman] Error 1
I seem to be missing a link library in my Makefile, but I have looked everywhere online and I can't seem to find it.
I have tried switching the order of the link libraries in the LIBS variable of my Makefile. I first tried putting -lopencv_tracking (where I assume the kalman filter functions are) at the end of the link list, and then I tried putting it second in the list (right in front of -lopencv_core). Both yielded the same link error.
Here is the Makefile that I am using
CC=g++
TARGET=kalman
SRC=kalman.cpp
LIBS=-lopencv_core -lopencv_tracking -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio -lopencv_objdetect
OBJ=kalman.o
%.o: %.cpp
$(CC) -c -o $# $< $(LIBS)
kalman: $(OBJ)
$(CC) -o $# $^ $(LIBS)
The program should build correctly with no errors
I found the answer, I was missing -lopencv_video in my LIBS
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}
Recently I build opencv as static library(by using BUILD_SHARED_LIBS=OFF) while dynamic libraries are already there, but at different location. And when I build may program I am getting many error. I am using command line for compiling the code, and look like below.
g++ -static -I$(OpenCV_Static_Build)/include/opencv -L$(OpenCV_Static_Build)/lib/ -g -o binary main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy
The error look like,
grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder12writeLibTiffERKNS_3MatERKSt6vectorIiSaIiEE+0x167): undefined reference to `TIFFSetField'
window_gtk.cpp:(.text.cvNamedWindow+0x29d): undefined reference to `g_type_check_instance_cast'
/usr/lib/gcc/i486-linux-gnu/4.4.3/libgcc_eh.a(unwind-dw2.o): In function `uw_init_context_1':
(.text+0x22f8): undefined reference to `pthread_once'
Those errors don't come from OpenCV (as one can tell from the function names) but from GLib and libpthread. Use the -lglib-2.0 -lpthread linker flags.
libcv-dev install
10.04
Any ideas as to where the following might be defined?
ahcarpenter#ahcarpenter-laptop:~$ g++ objectmarker.o -o objectmarker
objectmarker.o: In function `on_mouse(int, int, int, int, void*)':
objectmarker.cpp:(.text+0x12f): undefined reference to `cvCloneImage'
objectmarker.cpp:(.text+0x1d1): undefined reference to `cvRectangle'
objectmarker.cpp:(.text+0x1ea): undefined reference to `cvShowImage'
objectmarker.cpp:(.text+0x1f4): undefined reference to `cvReleaseImage'
objectmarker.o: In function `main':
objectmarker.cpp:(.text+0x391): undefined reference to `cvNamedWindow'
objectmarker.cpp:(.text+0x3aa): undefined reference to `cvSetMouseCallback'
objectmarker.cpp:(.text+0x4da): undefined reference to `cvLoadImage'
objectmarker.cpp:(.text+0x50f): undefined reference to `cvShowImage'
objectmarker.cpp:(.text+0x519): undefined reference to `cvWaitKey'
objectmarker.cpp:(.text+0x53f): undefined reference to `cvReleaseImage'
objectmarker.cpp:(.text+0x54e): undefined reference to `cvDestroyWindow'
objectmarker.cpp:(.text+0xd7f): undefined reference to `cvReleaseImage'
objectmarker.cpp:(.text+0xdf3): undefined reference to `cvDestroyWindow'
collect2: ld returned 1 exit status
I tried this and it worked for me:
sudo g++ -I/usr/include/opencv main.cpp -o main -lopencv_core -lopencv_imgproc
-lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d
-lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -I /lib/
-I /home/ubuntu/micros/opencv_directory/include/opencv
I got it from: https://askubuntu.com/questions/239891/opencv-program-wont-compile-quantal
It seems you're not linking against the OpenCV libraries; according to this guide, one way to compile an OpenCV program (after OpenCV has been properly configured) is
g++ `pkg-config opencv --cflags` my_code.cpp -o my_code `pkg-config opencv --libs`
If your C++ code is compiled in a separate step, you can probably drop the --cflags part.
You need to include libraries using pkg-config and cflags.
$ g++ -ggdb `pkg-config --cflags opencv` -o `basename filename.cpp .cpp` filename.cpp `pkg-config --libs opencv
see this link for more details http://www.jayrambhia.com/blog/2012/05/08/beginning-opencv/