Some RCpp example code works smooth within RStudio. In the C++ IDE Qt Creator segmentation faults (SIGSEGV
) occur instead, despite having fresh repositories, a modern GNU/Linux distro and modern g++ version.
This code works fine under RStudio, and gives me a segmentation fault in Qt Creator:
//main.cpp
#include <Rcpp.h>
int main() {
Rcpp::IntegerVector v(3);
}
Not just this code, but also code copied from the Rcpp test suites like, for example:
DataFrame createTwo(){
IntegerVector v = IntegerVector::create(1,2,3);
std::vector<std::string> s(3);
s[0] = "a";
s[1] = "b";
s[2] = "c";
return DataFrame::create(Named("a")=v, Named("b")=s);
}
I use qmake to create a Makefile, and use the code suggested by Dirk Eddelbuettel and Romain Francois as well:
## -*- mode: Makefile; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
##
## Qt usage example for RInside, inspired by the standard 'density
## sliders' example for other GUI toolkits
##
## This file can be used across operating systems as qmake selects appropriate
## values as needed, as do the R and R-related calls below. See the thread at
## http://ift.tt/1LUvmOj
## for discussion specific to Windows.
##
## Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
## build an app based on the one headers and two source files
TEMPLATE = app
## beyond the default configuration, also use SVG graphics
QT += svg
## comment this out if you need a different version of R,
## and set set R_HOME accordingly as an environment variable
R_HOME = $$system(R RHOME)
#message("R_HOME is" $$R_HOME)
## include headers and libraries for R
RCPPFLAGS = $$system($$R_HOME/bin/R CMD config --cppflags)
RLDFLAGS = $$system($$R_HOME/bin/R CMD config --ldflags)
RBLAS = $$system($$R_HOME/bin/R CMD config BLAS_LIBS)
RLAPACK = $$system($$R_HOME/bin/R CMD config LAPACK_LIBS)
## if you need to set an rpath to R itself, also uncomment
RRPATH = -Wl,-rpath,$$R_HOME/lib
## include headers and libraries for Rcpp interface classes
## note that RCPPLIBS will be empty with Rcpp (>= 0.11.0) and can be omitted
RCPPINCL = $$system($$R_HOME/bin/Rscript -e \"Rcpp:::CxxFlags\(\)\")
RCPPLIBS = $$system($$R_HOME/bin/Rscript -e \"Rcpp:::LdFlags\(\)\")
## for some reason when building with Qt we get this each time
## /usr/local/lib/R/site-library/Rcpp/include/Rcpp/module/Module_generated_ctor_signature.h:25: warning: unused parameter ‘classname
## so we turn unused parameter warnings off
## no longer needed with Rcpp 0.9.3 or later
#RCPPWARNING = -Wno-unused-parameter
## include headers and libraries for RInside embedding classes
RINSIDEINCL = $$system($$R_HOME/bin/Rscript -e \"RInside:::CxxFlags\(\)\")
RINSIDELIBS = $$system($$R_HOME/bin/Rscript -e \"RInside:::LdFlags\(\)\")
## compiler etc settings used in default make rules
QMAKE_CXXFLAGS += $$RCPPWARNING $$RCPPFLAGS $$RCPPINCL $$RINSIDEINCL
QMAKE_LIBS += $$RLDFLAGS $$RBLAS $$RLAPACK $$RINSIDELIBS $$RCPPLIBS
## addition clean targets
QMAKE_CLEAN += qtdensity Makefile
## My personal additions
QMAKE_CXXFLAGS += -Wall -Wextra -Weffc++ -std=c++11
QT += core
QT -= gui
TEMPLATE = app
SOURCES = main.cpp
Note that I use the C++11 standard with the QMAKE_CXXFLAGS += -std=c++11
flag. Removing this does not solve the problem.
As I said, the code passes all RStudio tests, but will crash on the same code with a segmentation fault in Qt Creator. All Rcpp repositories are fresh.
My G++ version is also the newest version under Lubuntu:
richel@druten:~/GitHubs/RibiLibraries$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/5/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.2.1-22ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-i386/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-i386 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-i386 --with-arch-directory=i386 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-targets=all --enable-multiarch --disable-werror --with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2)
My distro:
richel@druten:~/GitHubs/RibiLibraries$ uname -a
Linux druten 4.2.0-30-generic #36-Ubuntu SMP Fri Feb 26 00:57:19 UTC 2016 i686 athlon i686 GNU/Linux
Here I somewhat construct a stack trace, the debugger takes me to level 3
:
0 ?? 0xb7d10668
1 Rf_allocVector3 0xb7d11727
2 Rf_allocVector 0xb7d023be
3 Rcpp::Vector<13, Rcpp::PreserveStorage>::Vector Vector.h 129 0x804b214 <- Debugger takes me here
4 main main.cpp 5 0x804ac40
The critical piece of code is:
Vector( const int& size ) {
Storage::set__( Rf_allocVector( RTYPE, size) ) ; // <-- This line
init() ;
}
What could have gone wrong?
Aucun commentaire:
Enregistrer un commentaire