I am beginning using rinside and rcpp within c++. I just want to start from zero so my QT project has nothing but the creation of a RInside instance and I have a problem I cannot solve. I have only one dialog form in the project.
My project file:
QT += core gui
TARGET = rcpp-rinside
TEMPLATE = app
SOURCES += main.cpp\
dialog.cpp
HEADERS += dialog.h
FORMS += dialog.ui
INCLUDEPATH += C:\R\R-2.15.1\include
INCLUDEPATH += C:\R\R-2.15.1\library\Rcpp\include
INCLUDEPATH += C:\R\R-2.15.1\library\RInside\include
LIBS += -LC:\R\R-2.15.1\bin\i386 -lR
LIBS += -LC:\R\R-2.15.1\library\Rcpp\lib\i386\ -lRcpp
LIBS += -LC:\R\R-2.15.1\library\RInside\lib\i386\ -lRInside
The main file:
#include <QtGui/QApplication>
#include "dialog.h"
int main(int argc, char *argv[])
{
RInside R(argc, argv);
QApplication a(argc, argv);
Dialog w;
w.show();
return a.exec();
}
For the other files, there is nothing there because it's only an empty form. When I build this, I got a lot of errors like the following:
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x39c): undefined reference to `__gxx_personality_sj0'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x3bb): undefined reference to `_Unwind_SjLj_Register'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x419): undefined reference to `_Unwind_SjLj_Unregister'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x471): undefined reference to `_Unwind_SjLj_Resume'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x4cc): undefined reference to `__gxx_personality_sj0'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x4eb): undefined reference to `_Unwind_SjLj_Register'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x608): undefined reference to `_Unwind_SjLj_Unregister'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x64c): undefined reference to `_Unwind_SjLj_Unregister'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x746): undefined reference to `_Unwind_SjLj_Unregister'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x7f6): undefined reference to `_Unwind_SjLj_Resume'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x84c): undefined reference to `__gxx_personality_sj0'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x86b): undefined reference to `_Unwind_SjLj_Register'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x8c6): undefined reference to `_Unwind_SjLj_Unregister'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x9c5): undefined reference to `_Unwind_SjLj_Resume'
C:\R\R-2.15.1\library\RInside\lib\i386\/libRInside.a(RInside.o):RInside.cpp:(.text+0x9ec): undefined reference to `__gxx_personality_sj0'
I am using R-2.15.1, RInside 0.2.7, Rcpp 0.9.10, QT 4.8.0, MinGW 4.6.1.
You must use a version of Qt built with the same toolchain used for R -- ie the MinGW build of the compiler.
I did that once years as a proof of concept starting from the Qt sources.
Besides that, I would strongly suggest to start from the qtdensity.pro
file that ships with the examples of my RInside package.
You have to tell the linker to link against RInside before linking against Rcpp. See this rcpp-devel post.
For qtdensity to work under windows, you need to modify line 46 of the qtdensity.pro file:
QMAKE_LIBS += $$RLDFLAGS $$RBLAS $$RLAPACK $$RCPPLIBS $$RINSIDELIBS
and switch the order of $$RCPPLIBS and $$RINSIDELIBS:
QMAKE_LIBS += $$RLDFLAGS $$RBLAS $$RLAPACK $$RINSIDELIBS $$RCPPLIBS
You also have to replace single quotes with double quotes in the qtdensity.pro file, as mentioned. These modifications will be in the next version of RInside (currently 0.2.9).
In addition, you must have used the same compiler to build Rcpp & RInside and to compile your Qt application.
Just to share my "experiences" with Rcpp and Rinside until now in Windows 7 64 bit and Windows XP SP3 32 bit. I installed the latest version of R (2.15.1) and installed Rcpp and RInside from source.
install.packages("path/Rcpp_x.x.x.tar.gz",repos=NULL,type="source",INSTALL_opts="--no-multiarch")
- In win7, I could not install without the --no-multiarch option.
- I could compile all the standard examples of RInside in both systems (always with --arch32 in Makefile.win)
- I can run all the executable in Win7. In WinXP, I have the error "unable to load base package"
- for the QT example qtdensity, I don't have anymore the "__gxx_personality_sj0" and co. error (which is a little improvement). Instead, I have the following errors:
C:/R/R-2.15.1/library/RInside/lib/i386/libRInside.a(RInside.o):RInside.cpp:(.text+0xbd1): undefined reference to
Rcpp::Function::Function(std::string const&)' C:/R/R-2.15.1/library/RInside/lib/i386/libRInside.a(RInside.o):RInside.cpp:(.text+0xccd): undefined reference to
vtable for Rcpp::Language' C:/R/R-2.15.1/library/RInside/lib/i386/libRInside.a(RInside.o):RInside.cpp:(.text+0xcd9): undefined reference toRcpp::Language::update()' C:/R/R-2.15.1/library/RInside/lib/i386/libRInside.a(RInside.o):RInside.cpp:(.text+0xce1): undefined reference to
Rcpp::Function::~Function()' C:/R/R-2.15.1/library/RInside/lib/i386/libRInside.a(RInside.o):RInside.cpp:(.text+0xd2c): undefined reference to `Rcpp::DottedPair::operator'
which I believe is only related in libraries not properly included. - Another thing I found: the script dealing with headers and libs for rcpp and rinside in qtdensity.pro work only when I changed simple quotes to double quotes : instead of :
$$system($$R_HOME/bin/Rscript -e \'Rcpp:::CxxFlags()\')
I changed to :
$$system($$R_HOME/bin/Rscript -e \"Rcpp:::CxxFlags()\")
Still playing around with it and will let you know what's coming next :) Andry
来源:https://stackoverflow.com/questions/12280707/using-rinside-with-qt-in-windows