Search code examples
c++cqt5rpcqmake

How to compile rpcgen files with Qt classes?


I'm working on an assignment where we have to use RPCgen generated server and client .c files to exchange information about a shared drawing board. The drawing board was implemented using QtCreator and QtPainter.

The issue I'm having is that, when compiling, I get errors of undefined references both to xdr functions such as xdr_int and to functions in the class files I created inside QtCreator related to xdr. I think it's worth saying that the client/server independent code runs fine with the -ltirpc flag.

I've already tried adding the -ltirpc flag both directly in the makefile generated by the .pro + qmake, and only in the pro. file and then running through QtCreator. The LineArea function below is one of the undefined references and the first line, where it creates the client, is a reference to xdr function clnt_create.

LineArea::LineArea(char *hostname, QWidget *parent) : QWidget(parent)
{
    clnt = clnt_create(hostname, WHITEBOARD_PROG, WHITEBOARD_VERSION, "udp");
    if (clnt)
    {
        clnt_info = register_client_1(clnt_info, clnt);
        setAttribute(Qt::WA_StaticContents);
        press_start = false;
        pen_width = 2;
        pen_color = QColor(clnt_info->r, clnt_info->g, clnt_info->b);
        board = QImage(500, 500, QImage::Format_RGB32);
        board.fill(qRgb(255, 255, 255));
        board_real = board;
        update();
    }
}

Here's the latest attempt at adding the compile flag to qmake/.pro:

CONFIG += c++11

SOURCES += \
        LineArea.cpp \
        main.cpp \
        mainwindow.cpp \
        whiteboard_clnt.c \
        whiteboard_xdr.c

HEADERS += \
        LineArea.h \
        mainwindow.h \
        whiteboard.h

FORMS += \
        mainwindow.ui
#EXTRA FLAGS
QMAKE_CXXFLAGS += -ltirpc

Any help or suggestion is appreciated.

EDIT: these are the errors at compile time

g++ -Wl,-O1 -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o whiteboard LineArea.o main.o mainwindow.o moc_LineArea.o moc_mainwindow.o whiteboard_clnt.c whiteboard_xdr.c whiteboard.h   /usr/lib/libQt5Widgets.so /usr/lib/libQt5Gui.so /usr/lib/libQt5Core.so /usr/lib/libGL.so -lpthread   
/usr/bin/ld: LineArea.o: in function `LineArea::LineArea(char*, QWidget*)':
LineArea.cpp:(.text+0xa6f): undefined reference to `clnt_create'
/usr/bin/ld: /tmp/ccdM1OwC.o: in function `send_line_1':
whiteboard_clnt.c:(.text+0x43): undefined reference to `xdr_int'
/usr/bin/ld: /tmp/ccdM1OwC.o: in function `remove_client_1':
whiteboard_clnt.c:(.text+0x1cf): undefined reference to `xdr_int'
/usr/bin/ld: /tmp/cccxQLHU.o: in function `xdr_operands':
whiteboard_xdr.c:(.text+0x54): undefined reference to `xdr_int'
/usr/bin/ld: whiteboard_xdr.c:(.text+0x7e): undefined reference to `xdr_int'
/usr/bin/ld: whiteboard_xdr.c:(.text+0xa8): undefined reference to `xdr_int'
/usr/bin/ld: /tmp/cccxQLHU.o:whiteboard_xdr.c:(.text+0xd2): more undefined references to `xdr_int' follow
collect2: error: ld returned 1 exit status
make: *** [Makefile:410: whiteboard] Error 1

I'm running make manually, I've added the whiteboard_clnt.c whiteboard_xdr.c and whiteboard.h to the recipe at the makefile. Whithout them the same errors appear, except the xdr errors.

g++ -Wl,-O1 -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o whiteboard LineArea.o main.o mainwindow.o moc_LineArea.o moc_mainwindow.o   /usr/lib/libQt5Widgets.so /usr/lib/libQt5Gui.so /usr/lib/libQt5Core.so /usr/lib/libGL.so -lpthread   
/usr/bin/ld: LineArea.o: in function `LineArea::recvLines()':
LineArea.cpp:(.text+0x70): undefined reference to `consult_line_1'
/usr/bin/ld: LineArea.o: in function `LineArea::drawLineTo(QPoint const&)':
LineArea.cpp:(.text+0x7a0): undefined reference to `send_line_1'
/usr/bin/ld: LineArea.o: in function `LineArea::LineArea(char*, QWidget*)':
LineArea.cpp:(.text+0xa6f): undefined reference to `clnt_create'
/usr/bin/ld: LineArea.cpp:(.text+0xa86): undefined reference to `register_client_1'
collect2: error: ld returned 1 exit status
make: *** [Makefile:410: whiteboard] Error 1

Solution

  • QMAKE_CXXFLAGS += -ltirpc adds compiler flags, and compiler doesn't care about libraries. Assuming the lib name is correct and found without adding -L library search paths, this should work:

    LIBS += -ltirrp