4

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.

1
  • Also, you need to replace lib by libs in your .pro file. Nov 3, 2012 at 10:31

3 Answers 3

3

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.

5
  • Thank you for the answer Dirk. I do use a QT that I have built myself with MinGW. As for the qtdensity project, I am still learning it now but I want to start little by little with RInside and Rcpp. Can different versions of MinGW for R and QT be a problem ?? Sep 5, 2012 at 12:07
  • Yes they can. Start by rebuilding the working and complete example for Qt shipped with RInside; there is a reason it is included. It may need tweaks on the Windows side of the .pro though. Sep 5, 2012 at 12:11
  • After the "tweaking" in the .pro file, all the required libraries are found but I have the same errors as before (undefined reference to `__gxx_personality_sj0' ....). Do you think I have to rebuild R instead of using the windows installer provided ?? Sep 5, 2012 at 13:38
  • Not sure, but I would recommend using the same compiler etc across R and Qt, if you can. As I recall, I had it working so it can work but it is, like many things on Windows, fiddly. Please do report back, preferably on the rcpp-devel list. Sep 5, 2012 at 13:42
  • 1
    @AndrianiainaRakotondrajoa I faced the same problem today. Different versions of mingw for Qt and R, ARE, responsible for this error. As a solution I unzipped the desired version of mingw in Qt's mingw folder. This error is gone now. Nov 3, 2012 at 9:16
3

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.

1

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 tovtable for Rcpp::Language' C:/R/R-2.15.1/library/RInside/lib/i386/libRInside.a(RInside.o):RInside.cpp:(.text+0xcd9): undefined reference to Rcpp::Language::update()' C:/R/R-2.15.1/library/RInside/lib/i386/libRInside.a(RInside.o):RInside.cpp:(.text+0xce1): undefined reference toRcpp::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

1
  • 1
    Since this really isn't an answer, could you perhaps meaningfully append it to your question instead? Sep 7, 2012 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.