Mongodb Can';我找不到mongoc.h

Mongodb Can';我找不到mongoc.h,mongodb,mongo-c-driver,Mongodb,Mongo C Driver,在Ubuntu 16.04上安装Mongodb和C驱动程序后,我找不到mongoc.h sudo-apt-get-install-mongodb sudo apt get安装libmongoc-1.0-0 sudo apt get安装libbson-1.0 这是我得到的错误: gcc-o mtest mtest.c-I/usr/local/include/libbson-1.0-I/usr/local/include/libmongoc-1.0-lmongoc-1.0-lbson-1.0 mt

在Ubuntu 16.04上安装Mongodb和C驱动程序后,我找不到
mongoc.h

sudo-apt-get-install-mongodb
sudo apt get安装libmongoc-1.0-0
sudo apt get安装libbson-1.0
这是我得到的错误:

gcc-o mtest mtest.c-I/usr/local/include/libbson-1.0-I/usr/local/include/libmongoc-1.0-lmongoc-1.0-lbson-1.0
mtest.c:1:20:致命错误:mongoc.h:没有这样的文件或目录
编译终止。

我检查了磁盘,找不到文件。感谢您的提示。

如果您通过apt get安装,那么这些软件包几乎肯定不会安装到
/usr/local
,而是安装到普通的
/usr
。如果你跑了会怎么样

gcc -o mtest mtest.c -I/usr/include/libbson-1.0 -I/usr/include/libmongoc-1.0 -lmongoc-1.0 -lbson-1.0

另外,选择这些路径的正确方法是使用
pkg config
而不是硬编码,请参见我遇到了同样的问题,然后我按照以下步骤(对于Ubuntu)安装了库的包,如下所示:

1-检查是否已安装cmake,如果未安装:
$sudo apt get install cmake

2-要下载、构建源代码并安装库,请执行以下操作:

$ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.14.0/mongo-c-driver-1.14.0.tar.gz
$ tar xzf mongo-c-driver-1.14.0.tar.gz
$ cd mongo-c-driver-1.14.0
$ mkdir cmake-build
$ cd cmake-build
$ cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
3-要测试、编辑文件并另存为hello_mongo.c:

#include <mongoc/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;
  enter code here`bson_t *command, reply, *insert;
  bson_error_t error;
  char *str;
  bool retval;

  /*
   * Required to initialize libmongoc's internals
   */
  mongoc_init ();

  /*
   * Optionally get MongoDB URI from command line
   */
  if (argc > 1) {
     uri_string = argv[1];
  }

  /*
   * Safely create a MongoDB URI object from the given string
   */
  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;
  }

  /*
   * Create a new client instance
   */
  client = mongoc_client_new_from_uri (uri);
  if (!client) {
     return EXIT_FAILURE;
  }

  /*
   * Register the application name so we can track it in the profile logs
   * on the server. This can also be done from the URI (see other examples).
   */
  mongoc_client_set_appname (client, "connect-example");

  /*
   * Get a handle on the database "db_name" and collection "coll_name"
   */
  database = mongoc_client_get_database (client, "db_name");
  collection = mongoc_client_get_collection (client, "db_name", "coll_name");

  /*
   * Do work. This example pings the database, prints the result as JSON and
   * performs an insert
   */
  command = BCON_NEW ("ping", BCON_INT32 (1));

  retval = mongoc_client_command_simple (
     client, "admin", command, NULL, &reply, &error);

  if (!retval) {
     fprintf (stderr, "%s\n", error.message);
     return EXIT_FAILURE;
  }

  str = bson_as_json (&reply, NULL);
  printf ("%s\n", str);

  insert = BCON_NEW ("hello", BCON_UTF8 ("world"));

  if (!mongoc_collection_insert_one (collection, insert, NULL, NULL, &error)) {
     fprintf (stderr, "%s\n", error.message);
  }

  bson_destroy (insert);
  bson_destroy (&reply);
  bson_destroy (command);
  bson_free (str);

  /*
   * Release our handles and clean up libmongoc
   */
  mongoc_collection_destroy (collection);
  mongoc_database_destroy (database);
  mongoc_uri_destroy (uri);
  mongoc_client_destroy (client);
  mongoc_cleanup ();

  return EXIT_SUCCESS;
}

如果您使用的是raspberrypi 3,您可能使用的是mongodb 2.4.14,那么libbson和libmongoc库必须是1.7.0版。。看看这些:而且。

它开始用新的头文件进行攻击。。。gcc-o mtest-mtest.c-I/usr/include/libbson-1.0-I/usr/include/libmongoc-1.0-lmongoc-1.0-lbson-1.0在mtest.c:1:0:/usr/include/libmongoc-1.0/mongoc.h中包含的文件中:22:18:致命错误:bson.h:没有终止此类文件或目录编译。@Nisse,有什么替代方法安装apt获取的其他文件,这会解决我的问题吗?我只是想跟你说对不起,我不知道这个问题的答案。
$ gcc -o hello_mongoc hello_mongoc.c -I/usr/local/include/libbson-1.0 
-/usr/local/include/libmongoc-1.0 -lmongoc-1.0 -lbson-1.0
$ ./hello_mongoc