How do I resolve the linker error with 'cv::face::LBPHFaceRecognizer' in my OpenCV C++ code?

Unresolved External Source in OPENCV C++ Code with cv::face::LBPHFaceRecognizer

I have OPENCV code which acts a trainer that takes a directory full of face images. I am running this on OpenCV 4.2.0 with the OPENCV contrib 4.2.0 library. I am also running this on the newest version of Visual Studios.

#include <iostream> 
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <filesystem>
#include <opencv2/opencv.hpp>
#include <opencv2/face.hpp>
#include <opencv2/face/facerec.hpp>
using namespace cv;
using namespace cv::face;
using namespace std;
namespace fs = std::filesystem;

void assurePathExists(const string& path) {

int main() {
    Ptr<LBPHFaceRecognizer> recognizer = LBPHFaceRecognizer::create();
    CascadeClassifier detector;

    string datasetPath = "C:/Users/781932/Documents/STEMVisageVision";

    vector<Mat> faceSamples;
    vector<int> ids;

    vector<string> imagePaths;
    for (const auto& entry : fs::directory_iterator(datasetPath)) {
        if (entry.is_regular_file()) {

    for (const auto& imagePath : imagePaths) {
        Mat img = imread(imagePath, IMREAD_GRAYSCALE);
        int id = stoi(fs::path(imagePath).stem().string().substr(1));

        vector<Rect> faces;
        detector.detectMultiScale(img, faces);

        for (const auto& face : faces) {

    recognizer->train(faceSamples, ids);

    string trainerPath = "trainer/trainer.yml";

    return 0;

After cleaning and rebuilding the solution in VS, it is pretty apparent that the code itself is fine and has no errors. However, I am getting errors regarding the build.

Build started...
1>------ Build started: Project: 5_30_Trainer, Configuration: Debug x64 ------
1>5_30_Trainer.obj : error LNK2019: **unresolved external symbol "public: static struct cv::Ptr<class cv::face::LBPHFaceRecognizer> __cdecl cv::face::LBPHFaceRecognizer::create(int,int,int,int,double)" (?create@LBPHFaceRecognizer@face@cv@@SA?AU?$Ptr@VLBPHFaceRecognizer@face@cv@@@3@HHHHN@Z) referenced in function main**
1>C:\Users\781932\source\repos\5_30_Trainer\x64\Debug\5_30_Trainer.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "5_30_Trainer.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 9:21 AM and took 02.605 seconds ==========

There seems to be an issue with the the cv::face::LBPHFaceRecognizer class. I presume it’s a linker issue, but I do have everything included in the project properties. What is the issue?

there should be a opencv_face420.lib do you have it ?

(if you fail to find it, we have to get back at the cmake output)

I cannot find opencv_face420.lib in any of the folders said above. Where am I able to retrieve this file?

re-run cmake, show us the output (long, but nessecary !)

also maybe show, what you have so far in your linker settings

How do I re-run cmake for the output?

I have the path to the contrib’s face modules in the “Additional Library Directories” (C:\Users\781932\Downloads\opencv_contrib-4.2.0\opencv_contrib-4.2.0\modules\face\include;). As for the input section, I have “opencv_world420d.lib” in the “Additional Dependencies” section.

if that’s all, then you located one problem
(the world lib isnt enough, does not contain the face module)

this is an include, not a library path

all in all it looks, you never built opencv from src
(which you must, including the contrib modules)

ok, so why outdated 4.2 at all ?

hang on, …
you detect several faces in an image, yet you assume, they’re from the same person ?