简体   繁体   中英

problems compiling xmlrpc-c program

I'm trying out the examples in the xmlrpc-c documentation:

#include <stdio.h>
#include <xmlrpc.h>
#include <xmlrpc_server.h>
//#include <xmlrpc_server_abyss.h>
#include <xmlrpc_abyss.h>
#include <xmlrpc-c/base.h>
#include <xmlrpc-c/util.h>

static xmlrpc_value *
sample_add(xmlrpc_env *   const envP,
           xmlrpc_value * const paramArrayP, 
           void *         const serverContext) {

    xmlrpc_int32 x, y, z;

    /* Parse our argument array. */
    xmlrpc_decompose_value(envP, paramArrayP, "(ii)", &x, &y);
    if (envP->fault_occurred)
        return NULL;

    /* Add our two numbers. */
    z = x + y;

    /* Return our result. */
    return xmlrpc_build_value(envP, "i", z);
}



int 
main (int           const argc, 
      const char ** const argv) {

    xmlrpc_server_abyss_parms serverparm;
    xmlrpc_registry * registryP;
    xmlrpc_env env;

    xmlrpc_env_init(&env);

    registryP = xmlrpc_registry_new(&env);

    xmlrpc_registry_add_method(
        &env, registryP, NULL, "sample.add", &sample_add, NULL);

    serverparm.config_file_name = argv[1];
    serverparm.registryP = registryP;

    printf("Starting XML-RPC server...\n");

    xmlrpc_server_abyss(&env, &serverparm, XMLRPC_APSIZE(registryP));

    return 0;
}

I try to compile using gcc: gcc source.c

nohting fancy and I get: /tmp/ccfGuc6A.o: In function sample_add': source.c:(.text+0x38): undefined reference to xmlrpc_decompose_value' source.c:(.text+0x6d): undefined reference to xmlrpc_build_value' /tmp/ccfGuc6A.o: In function main': source.c:(.text+0x96): undefined reference to xmlrpc_env_init' source.c:(.text+0xa5): undefined reference to xmlrpc_registry_new' source.c:(.text+0xd8): undefined reference to xmlrpc_registry_add_method' source.c:(.text+0x117): undefined reference to xmlrpc_server_abyss' collect2: error: ld returned 1 exit status

these functions exist in the: /usr/include/xmlrpc-c/base.h whihc I have referenced:

include

I think I'm not passing the right options to link, I don't know how it's done though.

thanks

You definitely don't pass the correct argument for the linker. Just including a header file doesn't actually make the linker link with the library, you need to use the -l (lower-case L) option to tell the linker which libraries you need to link with, like

gcc source.c -lxmlrpc

I believe that xml-rpc-c comes with a helper program, intended to help you get the linking right. Its documented here

http://xmlrpc-c.sourceforge.net/doc/xmlrpc-c-config.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM