dimanche 28 juin 2020

LNK2019: unresolved external symbol even though other functions from the same header file work

I have a function named matToVector that is located in a namespace called sim that is located in header called SimilarityMeasures.h. When I call it in main.cpp it throws unresolved external even though function is declared and defined properly. Other functions in the same header file do work when called using sim::func. Below is the error code.

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "class std::vector<class std::complex<float>,class std::allocator<class std::complex<float> > > __cdecl sim::matToVector<class std::complex<float> >(class cv::Mat)" (??$matToVector@V?$complex@M@std@@@sim@@YA?AV?$vector@V?$complex@M@std@@V?$allocator@V?$complex@M@std@@@2@@std@@VMat@cv@@@Z) referenced in function main    bpv2    C:\Users\ASUS\source\repos\bpv2\bpv2\main.obj   1   

I included the header file that has the function in main.

#include "SimilarityMeasures.h"

Here is the function call in main.cpp

std::vector<std::complex<float>> imageVec = sim::matToVector<std::complex<float>>(xd);

Here is the function declaration in SimilarityMeasures.h

namespace sim {
    template <typename T>
    std::vector<T> matToVector(cv::Mat operand);
}

Here is the definition in SimilarityMeasures.cpp

template <typename T>
std::vector<T> sim::matToVector(cv::Mat operand) {   //https://stackoverflow.com/questions/62325615/opencv-data-of-two-mats-are-the-same-but-values-when-retrieved-with-matat-are
    std::vector<T> vecoper;
    uchar* pixelPtr = (uchar*)operand.data;
    int cn = operand.channels();
    cv::Scalar_<uchar> cnPixel;

    vecoper.push_back((T)operand.dims);
    for (int i = 0; i < (T)operand.dims; i++) {
        vecoper.push_back((T)operand.size[i]);
    }
    vecoper.push_back((T)operand.type());

    for (int i = 0; i < operand.total() * operand.elemSize(); i++) {
        vecoper.push_back((T)pixelPtr[i]);
    }

    return vecoper;
}

I only extracted the parts I thought necessary. If you need to see the whole header file or main.cpp or anything else just tell me.

Aucun commentaire:

Enregistrer un commentaire