2014-05-04 25 views
6

Non riesco a far funzionare Rcpp su Windows 8.1. Quando eseguo il seguente esempio minimo, ottengo un errore.Come far funzionare Rcpp?

> library(Rcpp) 
> evalCpp("1 + 1") 
g++ -m64 -I"C:/R/R-31~1.0/include" -DNDEBUG  -I"C:/R/R-3.1.0/library/Rcpp/include" - 
I"d:/RCompile/CRANpkg/extralibs64/local/include"  -O2 -Wall -mtune=core2 -c file11dc2120723d.cpp -o 
file11dc2120723d.o g++: not found make: *** [file11dc2120723d.o] Error 127 Warning message: running 
command 'make -f "C:/R/R-31~1.0/etc/x64/Makeconf" -f "C:/R/R-31~1.0/share/make/winshlib.mk" 
SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_97232.dll" WIN=64 TCLBIN=64 
OBJECTS="file11dc2120723d.o"' had status 2 
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, : 
    Error 1 occurred building shared library. 

Le prime due voci nel mio cammino sono: PATH = C: \ Rtools \ bin; c: \ Rtools \ gcc-4.6.3 \ bin;

R è installato in una directory C: \ R \ R-3.1.0

Rtools si trova nella directory C: \ r \ Rtools

Alcune informazioni aggiuntive:

> library(devtools) 
> find_rtools(T) 

Scanning path... 
ls : c:\Rtools\bin\ls.exe 
Scanning registry... 
Found c:/Rtools for 3.1 
VERSION.txt 
Rtools version 3.1.0.1942 
[1] TRUE 

> has_devel() 
"C:/R/R-31~1.0/bin/x64/R" --vanilla CMD SHLIB foo.c 

gcc -m64 -I"C:/R/R-31~1.0/include" -DNDEBUG  -I"d:/RCompile/CRANpkg/extralibs64/local/include"  
O2 -Wall -std=gnu99 -mtune=core2 -c foo.c -o foo.o 
gcc: not found 
make: *** [foo.o] Error 127 
Warning message: 
running command 'make -f "C:/R/R-31~1.0/etc/x64/Makeconf" -f "C:/R/R-31~1.0/share/make/winshlib.mk" 
SHLIB="foo.dll" WIN=64 TCLBIN=64 OBJECTS="foo.o"' had status 2 
Error: Command failed (1) 

> system('g++ -v') 
Warning message: 
running command 'g++ -v' had status 127 
+3

Qualcosa non va nel tuo percorso. Rileggi i manuali e riprova. È necessario riavviare il prompt cmd.exe e/o R/RStudio affinché le modifiche abbiano effetto. –

+0

Cosa offre 'system (" SET PATH ")'? –

+1

'system (" SET PATH ")' mi dà 'Messaggio di avviso: comando in esecuzione 'SET PATH' ha stato 127' – user3601715

risposta

0

Non sono sicuro se hai risolto il problema ma sembra che non sia installato gcc o g ++. Per Windows è possibile ottenere questi strumenti con MinGW.

  1. Installare MinGW che è possibile scaricare da here. La homepage per informazioni è here

  2. Una volta installato MinGW, è possibile aprire il 'Gestore installazione MinGW' e installare il cestino e lo sviluppatore per 'mingw32-gcc-g ++'.

  3. È quindi necessario aggiornare la variabile ambientale PATH per includere "C: \ MinGW \ bin" e "C: \ MinGW \ msys \ 1.0 \ bin".

  4. Riavviare la sessione R, non si può fare male a reinstallare anche 'Rcpp', e provare di nuovo require(Rcpp); evalCpp("1 + 1").

0

Ho avuto questo problema durante il tentativo di chiamare direttamente il codice C. Passando dal sistema di funzioni() a system2() risolto immediatamente.

0

che ho avuto difficoltà con l'installazione di RTools e aggiungendo RBuildTools al percorso:

Sys.setenv("PATH" = paste(Sys.getenv("PATH"), 
    "C:\\RBuildTools\\3.4\\bin", 
    "C:\\RBuildTools\\3.4\\mingw_32", 
    "C:\\RBuildTools\\3.4\\mingw_64", sep = ";")) 

non capisco queste cose, ma evidentemente soluzioni @cdeterman non funzionava per costruire il mio pacchetto mentre il suo esempio evalCpp("1 + 1") ha fatto.