मैं कुछ सी ++ कोड लिखने की कोशिश कर रहा हूं जो आरसीपीपी का उपयोग करते हुए विंडोज़ में कुछ ओएस-स्तरीय चीजों को एक्सेस करता है। जैसे ही मैं windows.h
या shlobj.h
शामिल करता हूं, मुझे संकलन त्रुटियों का एक गुच्छा मिलता है। जब मैं यह कोड चलाता हूं, यह काम करता है, इसलिए मुझे पता है कि मुझे कुछ मूलभूत बातें मिल रही हैं। लेकिन जब मैं विंडोज़ से संबंधित #include
लाइनों में से किसी एक को अपूर्ण करता हूं, तो यह काम नहीं करता है।विंडोज-विशिष्ट के साथ आरसीपीपी का उपयोग
library(inline)
inc <- '
#include <iostream>
#include <stdio.h>
// #include <windows.h>
// #include <shlobj.h>
using namespace std;
'
src <- '
cout << "foo\\n";
printf("foo2\\n");
return Rcpp::wrap(20);
'
fun <- cxxfunction(signature(),
includes = inc,
src, plugin="Rcpp")
fun()
नोट: जब मैं RStudio में इस चलाने के लिए, cout
और printf
से उत्पादन कंसोल में नहीं दिखाई, लेकिन जब मैं विंडोज RGui से चलाने, उत्पादन प्रकट नहीं होता है। मुझे लगता है कि आरजीईई पाठ आउटपुट को संभालने के तरीके के साथ ऐसा कुछ करने के लिए है।
जब मैं uncomment उन पंक्तियों में शामिल हैं, त्रुटियों मैं इस तरह दिखेगा:
In file included from c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/objbase.h:154:0,
from c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/ole2.h:16,
from c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/windows.h:94,
from file43c2f9e3518.cpp:22:
c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/objidl.h:598:52: error: macro "Realloc" requires 3 arguments, but only 2 given
c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/objidl.h:598:56: error: ISO C++ forbids initialization of member 'Realloc' [-fpermissive]
c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/objidl.h:598:56: error: making 'Realloc' static [-fpermissive]
... और इतने पर
यह कैसे काम करने के लिए पर कोई संकेत?
अद्यतन: मैं दूर जाना त्रुटियों में से कुछ पाने में कामयाब रहे, लेकिन कुछ रहते हैं।
मैं भी से http://tolstoy.newcastle.edu.au/R/e2/devel/06/11/1242.html
inc
कुछ सलाह का पालन करके Realloc
त्रुटियों की मिल के साथ प्रतिस्थापित किया जाना चाहिए:
inc <- '
#include <iostream>
#include <stdio.h>
// This is taken from http://tolstoy.newcastle.edu.au/R/e2/devel/06/11/1242.html
#include <R.h>
#undef Realloc
#define R_Realloc(p,n,t) (t *) R_chk_realloc((void *)(p), (size_t)((n) * sizeof(t)))
#include <shlobj.h>
using namespace std;
'
मैं भी, संकलक को -fpermissive
पास करके अन्य त्रुटियों से छुटकारा के रूप में मिल गया इस प्रश्न से: How to set g++ compiler flags using Rcpp and inline?
settings <- getPlugin("Rcpp")
settings$env$PKG_CXXFLAGS <- paste('-fpermissive',settings$env$PKG_CXXFLAGS,sep=' ')
fun <- cxxfunction(signature(), includes = inc,
src, plugin = "Rcpp",
settings = settings)
Sys.unsetenv('PKG_CXXFLAGS')
लेकिन वहां ar ई अभी भी कुछ त्रुटियाँ:
In file included from c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/objbase.h:154:0,
from c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/ole2.h:16,
from c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/shlobj.h:86,
from file43c267d3279.cpp:26:
c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/objidl.h:599:25: error: expected identifier before '(' token
c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/objidl.h:599:25: error: 'parameter' declared as function returning a function
c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/objidl.h:599:25: error: expected ')' before ',' token
धन्यवाद, आप सही हैं - यह आर और विंडोज हेडर के साथ एक सामान्य समस्या की तरह दिखता है। – wch