How to use libnfc in a Qt qamke project on macOS

62 views Asked by At

I have a Qt project (QMAKE) that works perfectly on my Raspberry Pi OS.

I would like to be able to run the same project on a MacBook. The project works, except when I include libnfc, I get the linker error:

:-1: error: Undefined symbols:

I have installed libnfc from GitHub, and I can successfully compile and run the examples (eg. npc-poll.c). Albeit they are pure C, while my code is C++.

main.cpp:

#include "mainwindow.h"
#include <QApplication>

#include <nfc/nfc.h>

int main(int argc, char *argv[])
{

    printf("TEST");
    const char *acLibnfcVersion = nfc_version();
    printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
    return 1;


    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

and I updated my .pro file to include this:

INCLUDEPATH += /usr/local/include
LIBS += -L/usr/local/lib -lnfc

There is a libnfc.dylib and a libnfc.a in the lib folder, so I really can't figure out what's wrong here.

I have tried to install libnfc with brew as well.

I also tried different settings in the .pro file, such as QMAKE_CXXFLAGS += -std=c++11 and QMAKE_LFLAGS += -L/usr/local/lib -lnfc

I also get this warning:

:-1: warning: ignoring file '/usr/local/lib/libnfc.6.dylib': found architecture 'arm64', required architecture 'x86_64'
1

There are 1 answers

0
Soren On

I found a workaround. I was using Qt5, and when I switched to Qt6, it worked out of the box.