我正在尝试为Windows设置Rcpp GSL ..我在这个主题上阅读了很多帖子,但我现在已经找不到解决方案了......对不起提前..
所以我在Windows 8.1上运行R 3.1。 Rcpp和Rcpp Armadillo都工作正常......
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RcppGSL_0.2.0 RcppArmadillo_0.4.300.0 Rcpp_0.11.1 foreign_0.8-61
loaded via a namespace (and not attached):
[1] tools_3.1.0
1)我确保R目录中没有空格 2)我安装了gnuwin32 3)我改变了我的Makevars.win
PKG_CPPFLAGS=-I$(LIB_GSL=C:/GnuWin32)/include -I../inst/include
PKG_LIBS=-L$(LIB_GSL=C:/GnuWin32)/lib -lgsl -lgslcblas $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()")
4)这是我的Makeconf,但请在这里说实话。我不知道这是什么意思
#-*- Makefile -*-
# $(R_HOME}/etc$(R_ARCH)/Makeconf
# Hand-edited version for gnuwin32.
ifdef DEBUG
DLLFLAGS=
DEBUGFLAG=-gdwarf-2
else
DLLFLAGS=-s
DEBUGFLAG=
endif
DLLFLAGS+= -static-libgcc
LINKFLAGS+= -static-libgcc
## Things which are substituted by fixed/Makefile (and also -O2 -> -O2)
WIN = 64
BINPREF =
# SYMPAT = 's/^.* [BCDRT] _/ /p' for 32-bit
# SYMPAT = 's/^.* [BCDRT] / /p' for 64-bit
SYMPAT = 's/^.* [BCDRT] / /p'
IMPDIR = bin/x64
# flags for multilib builds, for compilers, dlltool and windres
M_ARCH = -m64
DT_ARCH = -m i386:x86-64 --as-flags --64
RC_ARCH = -F pe-x86-64
# Used by packages tcltk and tkrplot
TCL_HOME = $(R_HOME)/Tcl
LOCAL_SOFT = d:/RCompile/CRANpkg/extralibs64/local
ifneq ($(strip $(LOCAL_SOFT)),)
LOCAL_CPPFLAGS = -I"$(LOCAL_SOFT)/include"
LOCAL_LIBS = -L"$(LOCAL_SOFT)/lib$(R_ARCH)" -L"$(LOCAL_SOFT)/lib"
endif
DLLTOOL = $(BINPREF)dlltool --as $(BINPREF)as $(DT_ARCH)
DLLTOOLFLAGS = -k
NM = $(BINPREF)nm
RESCOMP = $(BINPREF)windres $(RC_ARCH)
## MAIN_LD needs to be set by the package
LINKER = $(MAIN_LD)
## as a default
DLL = $(CC)
## Things defined in Renviron on Unix
SED = sed
TAR = tar
## Things defined in MkRules
CAT = cat
CP = cp
MKDIR = mkdir
RM = rm -f
SORT = sort
## For use in packages
GRAPHAPP_LIB = -lRgraphapp
TCL_VERSION = 85
ZLIB_LIBS = -lRzlib
AR = $(BINPREF)ar
## Used by packages 'maps' and 'mapdata'
AWK = gawk
BLAS_LIBS = -L"$(R_HOME)/$(IMPDIR)" -lRblas
C_VISIBILITY =
CC = $(BINPREF)gcc $(M_ARCH)
CFLAGS = -O2 -Wall $(DEBUGFLAG) -std=gnu99 -mtune=core2
CPICFLAGS =
CPPFLAGS =
CXX = $(BINPREF)g++ $(M_ARCH)
CXXCPP = $(CXX) -E
CXXFLAGS = -O2 -Wall $(DEBUGFLAG) -mtune=core2
CXXPICFLAGS =
CXX1X = $(BINPREF)g++ $(M_ARCH)
CXX1XFLAGS = -O2 -Wall $(DEBUGFLAG) -mtune=core2
CXX1XPICFLAGS =
CXX1XSTD = -std=c++0x
DYLIB_EXT = .dll
DYLIB_LD = $(DLL)
DYLIB_LDFLAGS = -shared
DYLIB_LINK = $(DYLIB_LD) $(DYLIB_LDFLAGS) $(LDFLAGS)
ECHO = echo
ECHO_C =
ECHO_N = -n
ECHO_T =
FC = $(BINPREF)gfortran $(M_ARCH)
FCFLAGS = -O2 $(DEBUGFLAG) -mtune=core2
# additional libs needed when linking with $(FC), e.g. on Solaris
FCLIBS =
F77 = $(BINPREF)gfortran $(M_ARCH)
F77_VISIBILITY =
FFLAGS = -O2 $(DEBUGFLAG) -mtune=core2
FLIBS = -lgfortran
FCPICFLAGS =
FPICFLAGS =
FOUNDATION_CPPFLAGS =
FOUNDATION_LIBS =
JAR =
JAVA =
JAVAC =
JAVAH =
# JAVA_HOME =
# JAVA_LD_LIBRARY_PATH =
JAVA_LIBS = -L"$(JAVA_HOME)/bin/client" -ljvm -ljvm-w32
JAVA_CPPFLAGS = -I"$(JAVA_HOME)/../include" -I"$(JAVA_HOME)/../include/win32"
LAPACK_LIBS = -L"$(R_HOME)/$(IMPDIR)" -lRlapack
## we only need this is if it is external, as otherwise link to R
LIBINTL=
LIBM = -lm
LIBR = -L"$(R_HOME)/$(IMPDIR)" -lR
LIBS = -lm
## needed by R CMD config
LIBnn = lib
LIBTOOL =
LDFLAGS =
## needed to build applications linking to static libR
# MAIN_LD =
# MAIN_LDFLAGS =
# MAIN_LINK = $(MAIN_LD) $(MAIN_LDFLAGS) $(LDFLAGS)
# don't have this: would 'mkdir -p' do?
# MKINSTALLDIRS = $(R_HOME)/bin/mkinstalldirs
## There is no ObjC support in the recommended toolchain,
## but if a toolchain had support, this it what it would be.
OBJC = $(CC)
OBJCFLAGS = -O2
OBJC_LIBS = -lobjc
OBJCXX =
R_ARCH = /x64
RANLIB = $(BINPREF)ranlib
SAFE_FFLAGS = -O2 -ffloat-store
SED = sed
## it seems some makes (but not ours) get upset if SHELL is set.
# SHELL = /bin/sh
SHLIB_CFLAGS =
SHLIB_CXXFLAGS =
SHLIB_CXXLD = $(CXX)
## ideally -shared -static-libstdc++, but not for gcc 4.2.1
SHLIB_CXXLDFLAGS = -shared
SHLIB_CXX1XLD = $(CXX1X)
SHLIB_CXX1XLDFLAGS = -shared
SHLIB_EXT = .dll
SHLIB_FCLD = $(FC)
## ideally -shared -static-libgfortran, but not for gcc 4.2.1
SHLIB_FCLDFLAGS = -shared
SHLIB_FFLAGS =
SHLIB_LD = $(CC)
SHLIB_LDFLAGS = -shared
SHLIB_LIBADD =
SHLIB_LINK = $(SHLIB_LD) -Wl,--export-all-symbols $(SHLIB_LDFLAGS) $(LDFLAGS)
SHLIB_OPENMP_CFLAGS = -fopenmp
SHLIB_OPENMP_CXXFLAGS = -fopenmp
SHLIB_OPENMP_FCFLAGS = -fopenmp
SHLIB_OPENMP_FFLAGS = -fopenmp
SHLIB_PTHREAD_FLAGS = -pthread
STRIP_LIBS = $(BINPREF)strip --strip-unneeded
STRIP_STATIC_LIBS = $(BINPREF)strip --strip-debug
TCLTK_CPPFLAGS = -I "$(TCL_HOME)/include" -DWin32
TCLTK_LIBS = -L"$(TCL_HOME)/bin64" -ltcl$(TCL_VERSION) -ltk$(TCL_VERSION)
STATIC_LIBR =
R_XTRA_CFLAGS =
R_XTRA_CPPFLAGS = -I"$(R_HOME)/include" -DNDEBUG
R_XTRA_CXXFLAGS =
R_XTRA_FFLAGS =
ALL_CFLAGS = $(R_XTRA_CFLAGS) $(PKG_CFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) $(CFLAGS)
ALL_CPPFLAGS = $(R_XTRA_CPPFLAGS) $(PKG_CPPFLAGS) $(CPPFLAGS) $($*-CPPFLAGS) $(CLINK_CPPFLAGS) $(LOCAL_CPPFLAGS)
ALL_CXXFLAGS = $(R_XTRA_CXXFLAGS) $(PKG_CXXFLAGS) $(CXXPICFLAGS) $(SHLIB_CXXFLAGS) $(CXXFLAGS)
ALL_OBJCFLAGS = $(PKG_OBJCFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) $(OBJCFLAGS)
ALL_OBJCXXFLAGS = $(PKG_OBJCXXFLAGS) $(CXXPICFLAGS) $(SHLIB_CXXFLAGS) $(OBJCXXFLAGS)
ALL_FFLAGS = $(R_XTRA_FFLAGS) $(PKG_FFLAGS) $(FPICFLAGS) $(SHLIB_FFLAGS) $(FFLAGS)
ALL_LIBS = $(PKG_LIBS) $(LOCAL_LIBS) $(SHLIB_LIBADD) $(LIBR) $(LIBINTL)
.SUFFIXES:
.SUFFIXES: .c .cc .cpp .d .f .f90 .f95 .m .mm .M .o .a .def .dll .exe .rc
.c.o:
$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c $< -o $@
.c.d:
@echo "making $@ from $<"
@$(CC) -std=gnu99 -MM $(ALL_CPPFLAGS) $< > $@
.cc.o:
$(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@
.cpp.o:
$(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@
.cc.d:
@echo "making $@ from $<"
@$(CXX) -M $(ALL_CPPFLAGS) $< > $@
.cpp.d:
@echo "making $@ from $<"
@$(CXX) -M $(ALL_CPPFLAGS) $< > $@
.m.o:
$(OBJC) $(ALL_CPPFLAGS) $(ALL_OBJCFLAGS) -c $< -o $@
.m.d:
@echo "making $@ from $<"
@$(OBJC) -MM $(ALL_CPPFLAGS) $< > $@
.mm.o:
$(OBJCXX) $(ALL_CPPFLAGS) $(ALL_OBJCXXFLAGS) -c $< -o $@
.M.o:
$(OBJCXX) $(ALL_CPPFLAGS) $(ALL_OBJCXXFLAGS) -c $< -o $@
.f.o:
$(F77) $(ALL_FFLAGS) -c $< -o $@
.f95.o:
$(FC) $(PKG_FCFLAGS) $(FCPICFLAGS) $(FCFLAGS) -c $< -o $@
.f90.o:
$(FC) $(PKG_FCFLAGS) $(FCPICFLAGS) $(FCFLAGS) -c $< -o $@
%.exe:
$(LINKER) $(LINKFLAGS) $($*-LINKFLAGS) -o $@ $^ $($*-LIBS) $(LOCAL_LIBS) $(LIBS)
%.dll:
@echo EXPORTS > $*.def
@$(NM) $^ | $(SED) -n $(SYMPAT) >> $*.def
$(SHLIB_LD) -shared $(DLLFLAGS) -o $@ $*.def $^ $(ALL_LIBS)
@$(RM) $*.def
lib%.dll.a: %.def
$(DLLTOOL) $(DLLTOOLFLAGS) $($*-DLLTOOLFLAGS) --dllname $*.dll --input-def $*.def --output-lib $@
%.a:
@$(RM) $@
$(AR) crs $@ $^
%.o: %.rc
$(RESCOMP) $(RESFLAGS) -i $< -o $@
5)我只是想重现GSL插图中的例子
#include <RcppGSL.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
extern "C" SEXP colNorm(SEXP sM) {
try {
RcppGSL::matrix<double> M = sM; // create gsl data structures from SEXP
int k = M.ncol();
Rcpp::NumericVector n(k); // to store results
for (int j = 0; j < k; j++) {
RcppGSL::vector_view<double> colview = gsl_matrix_column (M, j);
n[j] = gsl_blas_dnrm2(colview);
}
M.free() ;
return n; // return vector
} catch( std::exception &ex ) {
forward_exception_to_r( ex );
} catch(...) {
::Rf_error( "c++ exception (unknown reason)" );
}
return R_NilValue; // -Wall
}
我收到此错误
sourceCpp("gsltest.cpp")
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 gsltest.cpp -o gsltest.o gsltest.cpp:1:21: fatal error: RcppGSL.h: No such file or directory compilation terminated. make: *** [gsltest.o] Error 1 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_15178.dll" WIN=64 TCLBIN=64 OBJECTS="gsltest.o"' had status 2
Error in sourceCpp("gsltest.cpp") :
Error 1 occurred building shared library.
非常感谢..
答案 0 :(得分:2)
当您使用sourceCpp
时,如果RcppGSL
包在定义其内联插件方面做得很好,则需要添加以引入标题等...
// [[Rcpp::depends(RcppGSL)]]
线索在sourceCpp
给出的内容中,以下是您发布内容的摘录:
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 gsltest.cpp -o gsltest.o
gsltest.cpp:1:21: fatal error: RcppGSL.h: No such file or directory
答案 1 :(得分:2)
对于遇到相同问题的Windows用户,您需要按照以下步骤操作:
编辑你的Makevars.win,你准备好了
PKG_CPPFLAGS=-I$(LIB_GSL)/include -I../inst/include
PKG_LIBS=-L$(LIB_GSL)/lib/x64 -lgsl -lgslcblas
答案 2 :(得分:0)
如果在本地构建GSL太难了,请注意您也可以从this page下载CRAN本身使用的实际预建GSL库 - 您想要(大型)文件local300.zip
然后应该调整此处使用的环境变量LIB_GSL
:
edd@max:~$ cat svn/rcpp/pkg/RcppGSL/src/Makevars.win
## This assumes that the LIB_GSL variable points to working GSL libraries
PKG_CPPFLAGS=-I$(LIB_GSL)/include -I../inst/include
PKG_LIBS=-L$(LIB_GSL)/lib -lgsl -lgslcblas
edd@max:~$
我已经删除了我们不再需要的Rcpp库的Rscript
的现在冗余调用。