Ask Your Question

error LNK2019: unresolved external symbol "class cv::Mat __cdecl result(void)"

asked 2016-06-11 00:31:02 -0600

nolan gravatar image

updated 2016-06-11 11:36:47 -0600

i am trying to make this code work, but i cannot solve that error

Error 1 error LNK2019: unresolved external symbol "class cv::Mat __cdecl result(void)" (?result@@YA?AVMat@cv@@XZ) referenced in function "public: void __cdecl Classifier::TestData(float * *,int,int)" (?TestData@Classifier@@QEAAXPEAPEAMHH@Z)

i am linking libraries by name from the directory i included, in both debug (xxxd) and release (xxx).

OpenCV2.4.13 and visual studio 2013, i tried to use OpenCV3.1 but i couldn't change the SVM syntax because it is changed in the 3.1 version

  #ifndef CLASSIFIER_H
  #define   CLASSIFIER_H

  #include <cstdlib>
#include <vector>
#include <iostream>
#include <math.h>
#include <opencv2/ml/ml.hpp>

 using namespace std;
using namespace cv;

 class Classifier {
void Normalize(float **data_mat, int row, int col);
void TrainSVMClassifier(float **training_data, float* labels, int row, int col);
void TrainClassifier(float **training_data, int row, int col);
void TestData(float **testing_data, int row, int col);
void ClassifyData(float** testing_data, int row, int col);
void normalizeFV(float **data_mat, int row, int col);
virtual ~Classifier();
CvSVMParams params;
float *ref_mean;
float *ref_std_deviation;
float *calculateMean(float** data_mat, int row, int col);
float *calculateStdDeviation(float **data_mat, int row, int col, float *mean);

 #endif /* CLASSIFIER_H */


  #include "Classifier.h"

   Classifier::Classifier() {
   //Setting up SVM's parameters
    params.svm_type = CvSVM::C_SVC;
   params.kernel_type = CvSVM::LINEAR;
   params.gamma = 20;

    params.term_crit.type = CV_TERMCRIT_ITER | CV_TERMCRIT_EPS;
    params.term_crit.max_iter = 1000;
    params.term_crit.epsilon = 1e-6;


      float *Classifier::calculateStdDeviation(float **data_mat, int row, int col, float *mean) {
      float *std_deviation = (float *)calloc(col,sizeof(float));

       for(int i=0;i<row;i++){
       for(int j=0;j<col;j++){
         std_deviation[j] = std_deviation[j] + pow(data_mat[i][j]-mean[j],2);

   for(int j=0; j<col;j++){
      std_deviation[j] = sqrt(std_deviation[j]/row);
     return std_deviation;

    float *Classifier::calculateMean(float** data_mat, int row, int col) {
     float *mean = (float *)calloc(col, sizeof(float));

      for (int i = 0; i < row; i++) {
           for (int j = 0; j < col; j++) {
               mean[j] = mean[j] + data_mat[i][j];
       for (int j=0; j < col; j++) {
         mean[j] = mean[j] / row;
       return mean;

         void displayVector(float *v, int n){
                for(int i=0; i<n; i++){
                   cout<<v[i]<<" ";

               void Classifier::normalizeFV(float **data_mat, int row, int col){
                for(int i=0;i<row;i++){
               float mean =0;
                 float std_deviation = 0;
                for(int j=0;j<col;j++){
                  mean += data_mat[i][j];
                  mean /= col;
                 for(int j=0;j<col;j++){
               std_deviation = std_deviation + pow(data_mat[i][j]-mean,2);
                std_deviation /= col-1;
               for(int j=0;j<col;j++){
                    data_mat[i][j] = (data_mat[i][j]-mean)/std_deviation;

           void Classifier::Normalize(float** data_mat, int row, int col) {
        float *mean;
           float *std_deviation;
        mean = calculateMean(data_mat, row, col);
         std_deviation = calculateStdDeviation(data_mat, row, col, mean);
          for(int i=0;i<row;i++){
             for(int j=0; j<col;j++){
          data_mat[i][j] = (data_mat[i][j]-mean[j])/std_deviation[j];

         void Classifier::TrainClassifier(float** training_data, int row, int col){
          ref_mean = calculateMean(training_data, row, col);
          ref_std_deviation = calculateStdDeviation(training_data, row, col, ref_mean ...
edit retag flag offensive close merge delete


just curious, is this the 1st time, you're trying to use an SVM ?

(using float** for the data look quite weird)

berak gravatar imageberak ( 2016-06-11 01:20:19 -0600 )edit

yes it is the first time, how can i alter it?

nolan gravatar imagenolan ( 2016-06-11 01:41:50 -0600 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2016-06-11 01:18:53 -0600

berak gravatar image

updated 2016-06-11 01:21:24 -0600

if above is Classifier.h, there must be a Classifier.cpp too, containing the code for your functions.

make sure, you add that file to your project, so the code gets compiled and linked, too.

(it's not missing an external lib, just a file of yours)

edit flag offensive delete link more


yes this is Classifier.h, and there is a Classifier.cpp file. Both are in the project.

nolan gravatar imagenolan ( 2016-06-11 01:30:33 -0600 )edit

does Classifier.cpp have the code for

Mat result(void) { ... }


berak gravatar imageberak ( 2016-06-11 01:59:33 -0600 )edit

there is Mat result(); only, and i will add the whole Classifier.cpp code

nolan gravatar imagenolan ( 2016-06-11 11:31:14 -0600 )edit

just remove the braces:

Mat result;

you meant to construct a Mat, but compiler thinks, you want to call a function (most vexing parse)

berak gravatar imageberak ( 2016-06-12 00:29:48 -0600 )edit

Thank you very much, it didn't work for Mat result; but worked in this format float result=0;

nolan gravatar imagenolan ( 2016-06-12 15:24:58 -0600 )edit

answered 2018-04-16 00:36:17 -0600

The main reason of error 2019 for opencv project is because erroring in linking the lib files. Several reasons may: 1. path to the libs not correct 2. lib file name not correct 3. missing any lib files 4. x86 or x64 libs linking mistake 5. runtime library, i.e. multi-threaded debug dll (/mDd) , have to set correct in debug or release 6. checking your code, if missing :: before class member functions

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-06-11 00:31:02 -0600

Seen: 714 times

Last updated: Apr 16