Некоторые примеры кода RCpp работают в RStudio. В C++ IDE возникают ошибки сегментации Qt Creator (SIGSEGV
), несмотря на наличие свежих репозиториев, современного дистрибутива GNU/Linux и современной версии g ++.Rcpp :: Целочисленное создание Vector дает ошибку сегментации
Этот код прекрасно работает под RStudio, и дает мне ошибку сегментации в Qt Creator:
//main.cpp
#include <Rcpp.h>
int main() {
Rcpp::IntegerVector v(3);
}
Не только этот код, но и код, скопированный из тестовых наборов Rcpp, как, например:
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);
}
Я использую QMAKE создать Makefile и использовать код, предложенный Dirk Eddelbuettel и Ромен Франсуа, а также:
## -*- 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://thread.gmane.org/gmane.comp.lang.r.rcpp/4376/focus=4402
## 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
Обратите внимание, что я использую стандарт C++ 11 с флагом QMAKE_CXXFLAGS += -std=c++11
. Удаление этого не решает проблему.
Как я уже сказал, код передает все тесты RStudio, но будет сбой в том же коде с ошибкой сегментации в Qt Creator. Все репозитории Rcpp свежи.
версияMy G ++ также новая версия под Lubuntu:
[email protected]:~/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)
Мой Дистрибутив:
[email protected]:~/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
Здесь я несколько построить трассировку стека, отладчик берет меня к уровню 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
Критический фрагмент кода:
Vector(const int& size) {
Storage::set__(Rf_allocVector(RTYPE, size)) ; // <-- This line
init() ;
}
Что могло получиться не так?
Вы попробовали valgrind? – tobilocker