Post Go back to editing

Qt project with mcapi

Hi! I want to include MCAPI library in my Qt project. What should I do to make this?

I copied mcapi 2.0 headers into myproject/mcapi folder and append INCLUDEPATH += $$PWD/mcapi into .pro file. Also I appended DEPENDPATH += $$PWD/mcapi and unix:!macx: LIBS += -L$$PWD/mcapi/ -lmcapi. But I get error

mainwindow.o: In function `MainWindow::on_pushButton_2_clicked()':

../myproject/mainwindow.cpp:(.text+0x134): undefined reference to `mcapi_initialize(unsigned int, unsigned int, attributes_t const*, int const*, mcapi_info_t*, unsigned int*)'

collect2: ld returned 1 exit status

  • For anyone struggling with this that needs an actual answer instead of "don't use mcapi"... you'll need to add the following lines to your .pro project file:

        QMAKE_CFLAGS += -fPIC
        QMAKE_LFLAGS += -shared -fPIC

    I had the same issue where libmcapi would link fine when used outside a qt project in a normal Makefile, but i was getting undefined reference errors when trying to use it in a qt project. Adding the lines above in the pro file solves the problem.