1

I am trying to use the XML-RPC Client example in QT-Creator and am getting linking errors I can seem to be able to solve.

main.cpp:

#include <cstdlib>
#include <string>
#include <iostream>
#include <xmlrpc-c/girerr.hpp>
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/client_simple.hpp>

using namespace std;

int
main(int argc, char **) {

    if (argc-1 > 0) {
        cerr << "This program has no arguments" << endl;
        exit(1);
    }

    try {
        string const serverUrl("http://localhost:8080/RPC2");
        string const methodName("sample.add");

        xmlrpc_c::clientSimple myClient;
        xmlrpc_c::value result;

        myClient.call(serverUrl, methodName, "ii", &result, 5, 7);

        int const sum = xmlrpc_c::value_int(result);
            // Assume the method returned an integer; throws error if not

        cout << "Result of RPC (sum of 5 and 7): " << sum << endl;

   } catch (exception const& e) {
        cerr << "Client threw error: " << e.what() << endl;
    } catch (...) {
        cerr << "Client threw unexpected error." << endl;
    }

    return 0;
}

.pro file:

#-------------------------------------------------
#
# Project created by QtCreator 2013-04-02T00:25:47
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Mark2
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../usr/lib/release/ -lxmlrpc++
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../usr/lib/debug/ -lxmlrpc++
else:unix: LIBS += -L$$PWD/../../../../../../usr/lib/ -lxmlrpc++

INCLUDEPATH += $$PWD/../../../../../../usr/include
DEPENDPATH += $$PWD/../../../../../../usr/include


win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../usr/lib/release/ -lxmlrpc_client++
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../usr/lib/debug/ -lxmlrpc_client++
else:unix: LIBS += -L$$PWD/../../../../../../usr/lib/ -lxmlrpc_client++

INCLUDEPATH += $$PWD/../../../../../../usr/include
DEPENDPATH += $$PWD/../../../../../../usr/include

This is straight from http://xmlrpc-c.sourceforge.net/doc/#clientexamplepp

I am getting the following error:

error: undefined reference to `xmlrpc_c::clientSimple::clientSimple()'

As you can see I have included

xmlrpc-c/client_simple.hpp

which provides the definition of clientSimple. I have installed the xmlrpc library via the ubuntu software-center "libxmlrpc-c++4-dev" and "xmlrpc-api-utils"

What am I missing? Any help would be very appreciated!

  • How did you try to compile it, i.e. what .so or .a object did you include? – maditya Apr 01 '13 at 22:48
  • I did not include any .so or .a file in the source code. I thought that installing libxmlrpc-c++4-dev from the ubuntu software center would suffice. Am I wrong? – Alexander Langanke Apr 02 '13 at 07:22
  • I just downloaded the xmlrpc-c++ source tarball and compiled and installed the library. Same Problem. – Alexander Langanke Apr 03 '13 at 15:35
  • I have several libxmlrpc related .so or .a files in my /usr/lib/ directory. I just can't figure out what the step is that I am not getting.. – Alexander Langanke Apr 03 '13 at 16:16
  • I'm not familiar with QtCreator but how would you normally include a .so when using it? The error looks like the location of relevant .so isn't being told to the compiler at all – maditya Apr 03 '13 at 16:21
  • that's my problem. I am fairly new to programming and have not needed any libraries that were not included with QT up to now. I just don't know how to do that. This (http://stackoverflow.com/questions/718447/adding-external-library-into-qt-creator-project) for example does not tell me all that much.. – Alexander Langanke Apr 03 '13 at 17:22
  • That's understandable. From what I keep reading, there is a .pro file which is responsible for specifying the dependencies in your project. You should be able to open this file from within Qt Creator, and then add the relevant libraries from there. Could you post that file (e.g. edit your question or post a link)? Also http://qt-project.org/forums/viewthread/7597 might be useful to you ... – maditya Apr 03 '13 at 18:13
  • I have found the "add library" option. Have edited my post above to include the .pro file – Alexander Langanke Apr 03 '13 at 18:52
  • Thanks. The line `else:unix: LIBS += -L$$PWD/../../../../../../usr/lib/ -lxmlrpc_client++` specifies that your build system should look in the folder `$PWD/../../../../../../usr/lib/` for an object called `libxmlrpc_client++.so` or `libxmlrpc_client++.a`. Do you see either of these in that folder? (note that `-l` in that line is special, and `-lXYZ` in general expands to `libABC.so` or `libABC.a`. Also $PWD expands to the current working directory) – maditya Apr 03 '13 at 19:58
  • I'm guessing that the `$PWD/../../../../../../usr/lib/` ultimately becomes `/usr/lib`. Can you post the result of the following command? `ls /usr/lib | grep xmlrpc ; ls /usr/local/lib | grep xmlrpc ` – maditya Apr 03 '13 at 20:00
  • It finds lots of files.. too many to post here. Here is an excerpt: libxmlrpc_server++.a libxmlrpc_server_abyss.a libxmlrpc_server_abyss++.a libxmlrpc_server_abyss.so libxmlrpc_server_abyss++.so libxmlrpc_server_abyss.so.3 libxmlrpc_server_abyss.so.3.25 libxmlrpc_server_abyss++.so.7 libxmlrpc_server_abyss++.so.7.25 libxmlrpc_server_cgi.a libxmlrpc_server_cgi++.a libxmlrpc_server_cgi.so libxmlrpc_server_cgi++.so libxmlrpc_server_cgi.so. – Alexander Langanke Apr 03 '13 at 20:26
  • By the way: I selected the .so file in that path myself via a filepicker dialogue in QTCreator. The Path should be correct. – Alexander Langanke Apr 03 '13 at 20:27
  • In that case I'm sorry but I'm really not sure ... my hunch was that the .so was in /usr/local/lib instead of /usr/lib and therefore not getting linked. But if it's finding the right file and you're still getting the undefined reference issue, then it means the .so file simply doesn't contain the definition of that function. – maditya Apr 04 '13 at 00:34
  • My final guess is what I found here: http://xmlrpc-c.sourceforge.net/doc/libxmlrpc_client++.html#linking -- It says that libxmlrpc_client++ (which you have linked to) depends on a bunch of other libraries (which you haven't linked to). So it may be just a matter of also including those using the filepicker. – maditya Apr 04 '13 at 00:37
  • Thank you very much, I don't know how I missed those other files! It's linking and compiling now. How do I upvote you? – Alexander Langanke Apr 04 '13 at 05:39
  • You're welcome! Don't worry about it :) – maditya Apr 04 '13 at 06:08

0 Answers0