From dba02cc49f31cd00eeaf9f0865d5cfb61e846ba2 Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sat, 14 May 2016 08:04:11 +0100 Subject: [PATCH] R Dynamic Library (Windows) .. fixed up to work on Windows too. .. needed to add a couple of functions used by Windows; getRUser(), get_R_HOME() and getDLLVersion(). .. also needed to add a path to the DLL that included the address space (x64 or i386). --- src/R/REmbed.cpp | 1 - src/R/RLibrary.cpp | 16 ++++++++++++++-- src/R/RLibrary.h | 12 ++++++++++++ src/src.pro | 17 ++++++++++------- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/R/REmbed.cpp b/src/R/REmbed.cpp index 696e09483..e024938d6 100644 --- a/src/R/REmbed.cpp +++ b/src/R/REmbed.cpp @@ -83,7 +83,6 @@ REmbed::REmbed(const bool verbose, const bool interactive) : verbose(verbose), i setenv("R_HOME", configR_HOME.toLatin1().constData(), 1); } } - // fire up R const char *R_argv[] = {name, "--gui=none", "--no-save", "--no-readline", "--silent", "--vanilla", "--slave"}; diff --git a/src/R/RLibrary.cpp b/src/R/RLibrary.cpp index 672419bbf..edb82c447 100644 --- a/src/R/RLibrary.cpp +++ b/src/R/RLibrary.cpp @@ -130,6 +130,10 @@ Prot_GC_ptr_R_ResetConsole ptr_GC_ptr_R_ResetConsole; Prot_GC_ptr_R_FlushConsole ptr_GC_ptr_R_FlushConsole; Prot_GC_ptr_R_ClearerrConsole ptr_GC_ptr_R_ClearerrConsole; Prot_GC_ptr_R_Busy ptr_GC_ptr_R_Busy; +#else +Prot_GC_getDLLVersion ptr_GC_getDLLVersion; +Prot_GC_getRUser ptr_GC_getRUser; +Prot_GC_get_R_HOME ptr_GC_get_R_HOME; #endif // R data @@ -272,8 +276,11 @@ RLibrary::load() name = "lib/libR.so"; #endif #ifdef WIN32 - if (home == "") home = "/Program Files/R/"; - name = "bin/R.dll"; +#if defined(_M_X64) || defined (WIN64) + name = QString("bin/x64/R.dll"); +#else + name = QString("bin/i386/R.dll"); +#endif #endif #ifdef Q_OS_MAC if (home == "") home= "/Library/Frameworks/R.framework/Resources"; @@ -365,7 +372,12 @@ RLibrary::load() ptr_GC_ptr_R_FlushConsole = Prot_GC_ptr_R_FlushConsole(resolve("ptr_R_FlushConsole")); ptr_GC_ptr_R_ClearerrConsole = Prot_GC_ptr_R_ClearerrConsole(resolve("ptr_R_ClearerrConsole")); ptr_GC_ptr_R_Busy = Prot_GC_ptr_R_Busy(resolve("ptr_R_Busy")); + #else + ptr_GC_getDLLVersion = Prot_GC_getDLLVersion(resolve("getDLLVersion")); + ptr_GC_getRUser = Prot_GC_getRUser(resolve("getRUser")); + ptr_GC_get_R_HOME = Prot_GC_get_R_HOME(resolve("get_R_HOME")); #endif + // did it work -- resolve sets to false if symbols won't load return loaded; } diff --git a/src/R/RLibrary.h b/src/R/RLibrary.h index 801d9e380..f203ebdea 100644 --- a/src/R/RLibrary.h +++ b/src/R/RLibrary.h @@ -79,6 +79,13 @@ extern void (*(*ptr_GC_ptr_R_ResetConsole))(void); extern void (*(*ptr_GC_ptr_R_FlushConsole))(void); extern void (*(*ptr_GC_ptr_R_ClearerrConsole))(void); extern void (*(*ptr_GC_ptr_R_Busy))(int); +#else +typedef char *(*Prot_GC_getDLLVersion)(void); +typedef char *(*Prot_GC_getRUser)(void); +typedef char *(*Prot_GC_get_R_HOME)(void); +extern Prot_GC_getDLLVersion ptr_GC_getDLLVersion; +extern Prot_GC_getRUser ptr_GC_getRUser; +extern Prot_GC_get_R_HOME ptr_GC_get_R_HOME; #endif // R Data @@ -160,6 +167,11 @@ extern double *pGC_R_NaReal; // XXX TODO NaReal value #define ptr_R_ClearerrConsole (*ptr_GC_ptr_R_ClearerrConsole) #define ptr_R_Busy (*ptr_GC_ptr_R_Busy) #define R_registerRoutines GC_R_registerRoutines +#ifdef WIN32 +#define getDLLVersion (*ptr_GC_getDLLVersion) +#define getRUser (*ptr_GC_getRUser) +#define get_R_HOME (*ptr_GC_get_R_HOME) +#endif // data wrangling and manipulation #define Rf_allocVector GC_Rf_allocVector diff --git a/src/src.pro b/src/src.pro index 77ccbb8f5..071464abb 100644 --- a/src/src.pro +++ b/src/src.pro @@ -243,14 +243,17 @@ contains(DEFINES, "GC_WANT_R") { ## both 32 and 64 bit RCPPFLAGS = -I$$R_HOME/include - # 64 Bit Build - contains(QMAKE_TARGET.arch, x86_64):{ - LIBS += $$R_HOME/bin/x64/R.lib - } + !contains(DEFINES, "GC_WANT_R_DYNAMIC") { - # 32 Bit Build - !contains(QMAKE_TARGET.arch, x86_64):{ - LIBS += $$R_HOME/bin/i386/R.lib + # 64 Bit Build + contains(QMAKE_TARGET.arch, x86_64):{ + LIBS += $$R_HOME/bin/x64/R.lib + } + + # 32 Bit Build + !contains(QMAKE_TARGET.arch, x86_64):{ + LIBS += $$R_HOME/bin/i386/R.lib + } } } else {