mongodbubuntu-16.04mongo-c-driver

Problem executing code (C/Mongo C driver) on different installation than where first compiled


I have a program compiled and running on Ubuntu server 16.04, in C using Mongo C driver. This works without a problem. If I move this executable to a new installation, I get an error when executing;
testuser@usrv1604:~/bin$ ./error-example
./error-example: symbol lookup error: ./error-example: undefined symbol: mongoc_uri_new_with_error

Always the same error message. Please see simplified code example below:

#include <stdio.h>
#include <strings.h>
#include <mongoc.h>

int
main (int argc, char *argv[])
{
    const char *uri_string = "mongodb://localhost:27017";
    mongoc_uri_t *uri;
    mongoc_client_t *client;
    mongoc_database_t *database;
    mongoc_collection_t *collection;
    bson_t *command, reply, *insert;
    bson_t *b;
    bson_error_t error;

    mongoc_init ();

    uri = mongoc_uri_new_with_error (uri_string, &error);
    if (!uri) {
    fprintf (stderr,
        "failed to parse URI: %s\n"
        "error message:       %s\n",
        uri_string,
        error.message);
    return EXIT_FAILURE;
    }

    client = mongoc_client_new_from_uri (uri);
    if (!client) {
        fprintf(stderr, "mongoc_client_new_from_uri() failed \n");
        return EXIT_FAILURE;
    }

    mongoc_client_set_appname (client, "log-lme");
    database = mongoc_client_get_database (client, "sds");
    collection = mongoc_client_get_collection (client, "sds", "test");

//
// update db
//


    // clean up  
    mongoc_collection_destroy (collection);
    mongoc_database_destroy (database);
    mongoc_uri_destroy (uri);
    mongoc_client_destroy (client);
    mongoc_cleanup ();

    return EXIT_SUCCESS;
}

Solution

  • Please check the mongoc driver version installed on the target system. You must have version 1.8 or later to use this API: http://mongoc.org/libmongoc/1.8.0/mongoc_uri_new_with_error.html