我有一个使用Mongo C驱动程序在C上的Ubuntu服务器16.04上编译并运行的程序。这没有问题。如果将此可执行文件移至新安装,则执行时会出现错误;
testuser @ usrv1604:〜/ bin $ ./错误示例
./ 错误示例:符号查找错误:./错误示例:未定义符号:mongoc_uri_new_with_error
总是相同的错误消息。
请参见下面的简化代码示例:
#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;
}
答案 0 :(得分:0)
请检查目标系统上安装的mongoc驱动程序版本。您必须具有1.8或更高版本才能使用此API:http://mongoc.org/libmongoc/1.8.0/mongoc_uri_new_with_error.html