undefined reference to issue opencv3.2

asked 2017-01-06 12:16:23 -0600

sarmad gravatar image

updated 2017-01-09 03:25:20 -0600

Hi

I'm using opencv 3.2 on ubuntu 16.04 . these errors are showing on when I'm trying to compile my code :

here is the output of pkg-config --libs opencv :

-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 -lopencv_core

Update : the errors now resolved using this cmakelists:

cmake_minimum_required(VERSION 2.8) project( svm_test ) find_package( OpenCV REQUIRED ) include_directories( ${OpenCV_INCLUDE_DIRS} ) add_executable( svm_test svm_test.cpp ) target_link_libraries( svm_test ${OpenCV_LIBS} )

the compilation now showing :

Segmentation fault (core dumped)
_svm.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x1b): undefined reference to `cv::Mat::deallocate()'
_svm.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x78): undefined reference to `cv::fastFree(void*)'
CMakeFiles/blink_svm.dir/blink_svm.cpp.o: In function `cv::MatExpr::~MatExpr()':
_svm.cpp:(.text._ZN2cv7MatExprD2Ev[_ZN2cv7MatExprD5Ev]+0x25): undefined reference to    `cv::Mat::deallocate()'
_svm.cpp:(.text._ZN2cv7MatExprD2Ev[_ZN2cv7MatExprD5Ev]+0x8d): undefined reference to   `cv::fastFree(void*)'
_svm.cpp:(.text._ZN2cv7MatExprD2Ev[_ZN2cv7MatExprD5Ev]+0xac): undefined reference to   `cv::Mat::deallocate()'
_svm.cpp:(.text._ZN2cv7MatExprD2Ev[_ZN2cv7MatExprD5Ev]+0x112): undefined reference to `cv::fastFree(void*)'
_svm.cpp:(.text._ZN2cv7MatExprD2Ev[_ZN2cv7MatExprD5Ev]+0x12e): undefined reference to `cv::Mat::deallocate()'
_svm.cpp:(.text._ZN2cv7MatExprD2Ev[_ZN2cv7MatExprD5Ev]+0x188): undefined reference to `cv::fastFree(void*)'
CMakeFiles/blink_svm.dir/blink_svm.cpp.o: In function `main':
_svm.cpp:(.text.startup+0x53f): undefined reference to `cv::ml::SVM::create()'
_svm.cpp:(.text.startup+0x57f): undefined reference to `cv::String::allocate(unsigned long)'
_svm.cpp:(.text.startup+0x5c3): undefined reference to `cv::ml::TrainData::loadFromCSV(cv::String const&,   int, int, int, cv::String const&, char, char)'
_svm.cpp:(.text.startup+0x5cd): undefined reference to `cv::String::deallocate()'
 _svm.cpp:(.text.startup+0x5d5): undefined reference to `cv::String::deallocate()'
 svm.cpp:(.text.startup+0x682): undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
 svm.cpp:(.text.startup+0x70c): undefined reference to `cv::ml::TrainData::getTestSamples() const'
 svm.cpp:(.text.startup+0x844): undefined reference to `cv::operator==(cv::Mat const&, cv::Mat const&)'
 svm.cpp:(.text.startup+0x871): undefined reference to `cv::countNonZero(cv::_InputArray const&)'
 svm.cpp:(.text.startup+0x9cc): undefined reference to `cv::Mat::create(int, int const*, int)'
 svm.cpp:(.text.startup+0x9ea): undefined reference to `cv::Mat::operator=(cv::Scalar_<double> const&)'
 svm.cpp:(.text.startup+0xf9f): undefined reference to `cv::Formatter::get(int)'
 svm.cpp:(.text.startup+0x13ca): undefined reference to `cv::String::deallocate()'
 svm.cpp:(.text.startup+0x15c8): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
CMakeFiles/blink_svm.dir/build.make:106: recipe for target 'blink_svm' failed
make[2]: *** [blink_svm] Error 1
    CMakeFiles/Makefile2:215: recipe for target 'CMakeFiles/blink_svm.dir/all' failed
 make[1]: *** [CMakeFiles/blink_svm.dir/all] Error 2
edit retag flag offensive close merge delete

Comments

hi sarmad,

can you add, how you invoke it ? (your cmdline there)

berak gravatar imageberak ( 2017-01-06 21:58:10 -0600 )edit

Hi Berak.

I always compile it using :

cmake --build . or cmake --build . --config Release

. It works fine with other examples . Here is the cmake file , it is the same for dlib just added the example code . Cmakelists.txt

sarmad gravatar imagesarmad ( 2017-01-08 12:49:24 -0600 )edit