'QtCreator Getting Undefined Reference to Qt's own "QNearFieldTarget" Class while using CMake Build System

I'm trying to build an Android App to Debug the NFC communication. However, CMake doesn't seem to neither find nor link the required headers for NFC. QObject etc. works fine.

Minimal Reproducable Example:

nfc_controller.cpp: (Note: Successfully finds the QNearFieldManager header file.)

#include <NFCEngine/nfc/nfc_functions.h>
#include <QDebug>
#include <QtNfc/QNearFieldManager>
#include <QImage>
#include <NFCEngine/log.h>
#include <QFile>
#include <qdir.h>
#include <QStandardPaths>
#include <qobject.h>

NFCController::NFCController(QObject *parent) :
    QObject(parent),
    m_manager(new QNearFieldManager(this))
{
    if (!m_manager->isAvailable())
    {
        qWarning() << "NFC not available";
        return;
    }
    .
    .
    .
    More work here
}

Source Level CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)

project(nfctest VERSION 0.1 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 Core Nfc Quick Qml Widgets REQUIRED COMPONENTS Core Quick)

message(STATUS "###DEBUG: NFC: ${Nfc} ")
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick)

set(PROJECT_SOURCES     

      # Source Files
        "main.cpp"
        "NFC/nfc_controller.cpp"

       # Header Files
        "NFC/nfc_controller.h"

        "qml.qrc"
)

Error I Get When I Try To Build the Project:

error: undefined reference to QNearFieldManager::*

P.S.: When I try to print found NFC packages name after find_package() in CMakeLists.txt, it doesn't print anything. Which I think the cause of the problem. Shouldn't it throw an exception since it is tagged as REQUIRED?

Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source