Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mongoc驱动程序安装问题:test.c错误:mongoc.h:没有这样的文件或目录_C_Mongodb_Installation_Mongo C Driver - Fatal编程技术网

mongoc驱动程序安装问题:test.c错误:mongoc.h:没有这样的文件或目录

mongoc驱动程序安装问题:test.c错误:mongoc.h:没有这样的文件或目录,c,mongodb,installation,mongo-c-driver,C,Mongodb,Installation,Mongo C Driver,== 已安装: mongo-c-driver-1.1.0 /usr/src/mongo-c-driver-1.1.0/src/mongoc 问题:头文件位于同一目录中,仍然无法获取 ===== 代码: #包括 #包括 int 主(内部argc, 字符*argv[] 端口=(argc==3)?atoi(argv[2]):27017; if(strncmp(argv[1],“mongodb://”,10)==0){ 主机_和_端口=bson_strdup(argv[1]); }否则{ 主机和端

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

问题:头文件位于同一目录中,仍然无法获取

=====


代码:

#包括
#包括
int
主(内部argc,
字符*argv[]
端口=(argc==3)?atoi(argv[2]):27017;
if(strncmp(argv[1],“mongodb://”,10)==0){
主机_和_端口=bson_strdup(argv[1]);
}否则{
主机和端口=bson\u strdup\u printf(“mongodb://%s:%hu”,argv[1],端口);
}
client=mongoc\u client\u new(主机和端口);
如果(!客户端){
fprintf(stderr,“无效主机名或端口:%s\n”,主机和端口);
返回2;
}
bson_init(&ping);
bson_append_int32(&ping,“ping”,4,1);
数据库=mongoc_客户端_获取_数据库(客户端,“测试”);
cursor=mongoc_database_命令(database,0,0,1,0,&ping,NULL,NULL);
if(mongoc\u光标\u下一步(光标和回复)){
str=bson_as_json(回复,空);
fprintf(stdout,“%s\n”,str);
无bson_(str);
}else if(mongoc\u游标\u错误(游标和错误)){
fprintf(标准,“Ping失败:%s\n”,错误消息);
返回3;
}
mongoc_cursor_destroy(cursor);
bson_销毁(&ping);
mongoc_客户_销毁(客户);
bson_空闲(主机_和_端口);
返回0;
}
====

编译步骤需要一个-I.参数,以便在同一目录中找到头文件
链接步骤“可能”需要非标准库位置的“-L”参数
链接步骤需要一个'-lgcc-o menu menu.c$(pkg config--cflags--libs libmongoc-1.0)

已解决

#包含#包含int main(int argc,char*argv[]){mongoc_数据库(u t*数据库);mongoc_游标(u t*游标);mongoc_客户端(u t*客户端);int main(int argc,char*argv[]){mongoc_database_t*database;mongoc_cursor_t*cursor;mongoc_client_t*client;const bson_t*reply;uint16_t port;bson_error_t error;bson_ping;char*host_和_port;char*str;尝试将
\include
更改为
\include“mongoc.h”
try,但现在找不到bson.h。哪个头文件包含bson…函数的原型?关联库(及其名称)位于哪里?
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)
#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;
}
the compile step needs a -I. parameter so it will find the header file in the same directory

The link step 'may' need a '-L<pathToLibrary> parameter of non standard library location
the link step needs a '-l<short name of mongoc library' parameter so the library will be included