Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.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
rcpp和mongodb c++;驱动程序编译错误realloc冲突?_Mongodb_Rcpp - Fatal编程技术网

rcpp和mongodb c++;驱动程序编译错误realloc冲突?

rcpp和mongodb c++;驱动程序编译错误realloc冲突?,mongodb,rcpp,Mongodb,Rcpp,我试图在Rcpp中编译代码,其中包括。我已经能够独立编译C++代码,但是当我为MunGDB驱动程序包含头并使用SoeCeCppp()函数时,我会出错。会话信息: > sessionInfo() R version 3.2.1 (2015-06-18) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 14.04.2 LTS locale: [1] LC_CTYPE=en_GB.UTF-8 LC_NUME

我试图在Rcpp中编译代码,其中包括。我已经能够独立编译C++代码,但是当我为MunGDB驱动程序包含头并使用SoeCeCppp()函数时,我会出错。会话信息:

> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.2 LTS

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Rcpp_0.12.0

loaded via a namespace (and not attached):
[1] tools_3.2.1
< > C++代码低于<> >文件= HW.CPP] < /COD>

#include <R.h>
#include <Rcpp.h>
#include "mongo/client/dbclient.h" // for the driver
#include <cstdlib>
#include <iostream>
#include <vector>
#include <iomanip>

using namespace Rcpp;

// [[Rcpp::export]]
SEXP hw(){
    std::cout << "Hello Word" << std::endl;
    return Rcpp::wrap("Hello World!");
}
#包括
#包括
#为驱动程序包括“mongo/client/dbclient.h”//
#包括
#包括
#包括
#包括
使用名称空间Rcpp;
//[[Rcpp::导出]]
SEXP-hw(){

std::cout非常感谢Kevin,我按照您的建议使用ifdef/unde修改了标题,代码正常工作:

#include "mongo/client/dbclient.h" // for the driver
#ifdef Realloc
#undef Realloc
#endif
#include <R.h>
#include <Rcpp.h> 
...
#为驱动程序包括“mongo/client/dbclient.h”//
#ifdef Realloc
#undef Realloc
#恩迪夫
#包括
#包括
...

看起来R和mongodb驱动程序正在争夺
Realloc
符号。您可能需要尝试使用include order、取消定义/重新定义冲突的宏,等等。。。
In file included from /usr/local/include/mongo/bson/oid.h:23:0,
                 from /usr/local/include/mongo/bson/bsonelement.h:26,
                 from /usr/local/include/mongo/bson/bsonobj.h:27,
                 from /usr/local/include/mongo/client/bulk_operation_builder.h:20,
                 from /usr/local/include/mongo/client/dbclientinterface.h:29,
                 from /usr/local/include/mongo/client/dbclient_rs.h:23,
                 from /usr/local/include/mongo/client/dbclient.h:59,
                 from hw.cpp:3:
/usr/local/include/mongo/bson/util/builder.h:58:41: error: macro "Realloc" requires 3 arguments, but only 2 given
         void* Realloc(void *p, size_t sz) { return realloc(p, sz); }
                                         ^
/usr/local/include/mongo/bson/util/builder.h:69:41: error: macro "Realloc" requires 3 arguments, but only 2 given
         void* Realloc(void *p, size_t sz) { 
                                         ^
/usr/local/include/mongo/bson/util/builder.h:263:47: error: macro "Realloc" requires 3 arguments, but only 2 given
             data = (char *) al.Realloc(data, a);
                                               ^
/usr/local/include/mongo/bson/util/builder.h:58:68: error: expected ‘;’ at end of member declaration
         void* Realloc(void *p, size_t sz) { return realloc(p, sz); }
                                                                    ^
In file included from /usr/share/R/include/R.h:50:0,
                 from hw.cpp:1:
/usr/share/R/include/R_ext/RS.h:64:37: error: expected identifier before ‘(’ token
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                     ^
/usr/share/R/include/R_ext/RS.h:64:47: error: ‘parameter’ declared as function returning a function
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                               ^
/usr/share/R/include/R_ext/RS.h:64:50: error: expected ‘)’ before ‘,’ token
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                                  ^
In file included from /usr/local/include/mongo/bson/oid.h:23:0,
                 from /usr/local/include/mongo/bson/bsonelement.h:26,
                 from /usr/local/include/mongo/bson/bsonobj.h:27,
                 from /usr/local/include/mongo/client/bulk_operation_builder.h:20,
                 from /usr/local/include/mongo/client/dbclientinterface.h:29,
                 from /usr/local/include/mongo/client/dbclient_rs.h:23,
                 from /usr/local/include/mongo/client/dbclient.h:59,
                 from hw.cpp:3:
/usr/local/include/mongo/bson/util/builder.h:58:45: error: expected primary-expression before ‘return’
         void* Realloc(void *p, size_t sz) { return realloc(p, sz); }
                                             ^
/usr/local/include/mongo/bson/util/builder.h:58:45: error: expected ‘}’ before ‘return’
/usr/local/include/mongo/bson/util/builder.h:58:45: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘void*’ in initialization
/usr/local/include/mongo/bson/util/builder.h:58:45: error: expected ‘;’ before ‘return’
/usr/local/include/mongo/bson/util/builder.h:79:9: error: expected ‘;’ at end of member declaration
         }
         ^
In file included from /usr/share/R/include/R.h:50:0,
                 from hw.cpp:1:
/usr/share/R/include/R_ext/RS.h:64:37: error: expected identifier before ‘(’ token
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                     ^
/usr/share/R/include/R_ext/RS.h:64:47: error: ‘parameter’ declared as function returning a function
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                               ^
/usr/share/R/include/R_ext/RS.h:64:50: error: expected ‘)’ before ‘,’ token
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                                  ^
In file included from /usr/local/include/mongo/bson/oid.h:23:0,
                 from /usr/local/include/mongo/bson/bsonelement.h:26,
                 from /usr/local/include/mongo/bson/bsonobj.h:27,
                 from /usr/local/include/mongo/client/bulk_operation_builder.h:20,
                 from /usr/local/include/mongo/client/dbclientinterface.h:29,
                 from /usr/local/include/mongo/client/dbclient_rs.h:23,
                 from /usr/local/include/mongo/client/dbclient.h:59,
                 from hw.cpp:3:
/usr/local/include/mongo/bson/util/builder.h:70:13: error: expected primary-expression before ‘if’
             if( p == buf ) {
             ^
/usr/local/include/mongo/bson/util/builder.h:70:13: error: expected ‘}’ before ‘if’
/usr/local/include/mongo/bson/util/builder.h:70:13: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘void*’ in initialization
/usr/local/include/mongo/bson/util/builder.h:70:13: error: expected ‘;’ before ‘if’
In file included from /usr/share/R/include/R.h:50:0,
                 from hw.cpp:1:
/usr/local/include/mongo/bson/util/builder.h: In member function ‘void mongo::_BufBuilder<Allocator>::kill()’:
/usr/share/R/include/R_ext/RS.h:64:24: error: expected unqualified-id before ‘(’ token
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                        ^
/usr/local/include/mongo/bson/util/builder.h: In member function ‘void mongo::_BufBuilder<Allocator>::reset(int)’:
/usr/share/R/include/R_ext/RS.h:64:24: error: expected unqualified-id before ‘(’ token
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                        ^
make: *** [hw.o] Error 1
g++ -I/usr/share/R/include -DNDEBUG    -I"/home/myName/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include" -I"/home/myName/code/C++/mondodb"   -pthread -lmongoclient -lboost_thread -lboost_system -lboost_regex -fpic  -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -c hw.cpp -o hw.o
Error in sourceCpp("hw.cpp") : Error 1 occurred building shared library.
#include "mongo/client/dbclient.h" // for the driver
#ifdef Realloc
#undef Realloc
#endif
#include <R.h>
#include <Rcpp.h> 
...