c - mongo c驱动安装问题: test. c错误: mongoc. h:没有那个文件或目录

标签 c mongodb installation mongo-c-driver

== 已安装: mongo-c-driver-1.1.0 /usr/src/mongo-c-driver-1.1.0/src/mongoc

issue : header file is in same direcroty still not getting .

=====

mongo c driver install issue : test.c error: mongoc.h: No such file or directory
root@webrtc mongoc]# vim  test.c
[root@webrtc mongoc]# gcc CFLAGS=-std=c99 test.c 192.168.0.181 27017 -o test.o
gcc: CFLAGS=-std=c99: No such file or directory
gcc: 192.168.0.181: No such file or directory
gcc: 27017: No such file or directory
test.c:18:20: error: mongoc.h: No such file or directory
test.c: In function ‘main’:
test.c:26: error: ‘mongoc_database_t’ undeclared (first use in this function)
test.c:26: error: (Each undeclared identifier is reported only once
test.c:26: error: for each function it appears in.)
test.c:26: error: ‘database’ undeclared (first use in this function)
test.c:27: error: ‘mongoc_cursor_t’ undeclared (first use in this function)
test.c:27: error: ‘cursor’ undeclared (first use in this function)

代码:

http://code-trick.com/mongodb-c-driver-examples/

https://github.com/mongodb/mongo-c-driver/releases

#include <mongoc.h>
#include <stdio.h>
int
main (int   argc,
      char *argv[])

   port = (argc == 3) ? atoi(argv[2]) : 27017;

   if (strncmp (argv[1], "mongodb://", 10) == 0) {
      host_and_port = bson_strdup (argv [1]);
   } else {
      host_and_port = bson_strdup_printf("mongodb://%s:%hu", argv[1], port);
   }

   client = mongoc_client_new(host_and_port);

   if (!client) {
      fprintf(stderr, "Invalid hostname or port: %s\n", host_and_port);
      return 2;
   }
   bson_init(&ping);
   bson_append_int32(&ping, "ping", 4, 1);
   database = mongoc_client_get_database(client, "test");
   cursor = mongoc_database_command(database, 0, 0, 1, 0, &ping, NULL, NULL);
   if (mongoc_cursor_next(cursor, &reply)) {
      str = bson_as_json(reply, NULL);
      fprintf(stdout, "%s\n", str);
      bson_free(str);
   } else if (mongoc_cursor_error(cursor, &error)) {
      fprintf(stderr, "Ping failure: %s\n", error.message);
      return 3;
   }

   mongoc_cursor_destroy(cursor);
   bson_destroy(&ping);
   mongoc_client_destroy(client);
   bson_free(host_and_port);

   return 0;
}

=====

最佳答案

gcc -o menu menu.c $(pkg-config --cflags --libs libmongoc-1.0) 解决了

关于c - mongo c驱动安装问题: test. c错误: mongoc. h:没有那个文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31531411/

相关文章:

mongodb - 什么是 MongoDB 中的光标?

wpf - 适用于 WinXP + WPF + .NET 4.0 的 VS 安装项目安装程序的最佳简单替代品是什么?

C - 编译器在已经使用 '->' 时要求使用 '->'

javascript - 使用 JavascriptCore 创建构造函数

c - 在优化和不优化的情况下访问越界索引

oracle11g - Oracle 11G XE安装错误: Database Configuration failed

service - WiX - 修改已安装产品后重新启动服务

c - 使用两个 while 循环打印一个充满 "#"的方形图案

node.js - Mongoose findById 没有返回所有字段

java - 尽管没有重叠,但 Mongo DuplicateKey 错误