[Rcpp-devel] Rcpp C++ code debug / Calling Rcpp in a C++ environment

Jing Peng pengjing at live.com
Sat Jul 12 04:56:14 CEST 2014


Hi KK,

Thanks for your advice! I actually managed to get it work, by creating an
embeeded R instance before calling the Rcpp function. I didn't post the
solution yet because it is still not clear to me why that fixes the problem.

1) I compiled the code with an IDE, so I didn't post the command. I can't
live without an IDE:)

2) The C++ code to be debug used some handy Rcpp data structure, so I need
to link to Rcpp. That can be avoid, but will be less convenient.

Jing


New code:
#include <iostream>
#include <Rcpp.h>
#include <RInside.h>
using namespace std;
using namespace Rcpp;
int main(int argc, char** argv) {
    cout<<"Hello World!"<<endl;
    RInside R(argc, argv);   // Error disappears if creating an embedded R
instance because calling Rcpp functions
    CharacterVector x = CharacterVector::create( "foo", "bar" ); // problem
occurs here
    cout<<"Done!"<<endl;
    return 0;
}


On Fri, Jul 11, 2014 at 11:51 AM, Qiang Kou <qkou at umail.iu.edu> wrote:

> Hi,
>
> I don't have a Windows developing environment just now, so I can not
> figure out what is wrong. I can try in the weekends.
>
> Just little personal advice.
>
> (1) Maybe you should also put the compiling commands here, not only the
> output. It may be easier to see your configuration and the problem.
>
> (2) Since you want to debug in a pure C++ environment, why not remove all
> the code related to R and Rcpp? As my personal habit, I develop and debug
> pure C++ code first, then integrate with R.
>
> Best,
>
> KK
>
>
> On Wed, Jul 9, 2014 at 8:41 PM, Jing Peng <pengjing at live.com> wrote:
>
>> Hi All,
>>
>> I am trying to debug the C++ code of an R package in a pure C++
>> environment. That way, I can put aside the interaction between R and C++.
>>
>> However, I found I was not able to setup Rcpp properly after two days of
>> effort. I followed the following instructions for Eclipse and Netbeans,
>> respectively.
>>
>> Eclipse:
>> http://stackoverflow.com/questions/12886517/how-to-set-up-eclipse-statet-rcpp-on-windows
>> Netbeans:
>> http://cdrv.wordpress.com/2012/11/12/setting-up-netbeans-to-work-with-rcpp-and-compiling-rcpp-code-for-beginners/
>>
>> Test code:
>>
>> #include <iostream>
>> #include <Rcpp.h>
>> using namespace std;
>> using namespace Rcpp;
>> int main(int argc, char** argv) {
>>     cout<<"Hello World!"<<endl;
>>     CharacterVector x = CharacterVector::create( "foo", "bar" ); //
>> problem occurs here
>>     cout<<"Done!"<<endl;
>>     return 0;
>> }
>>
>> Platform: Windows 7 x64
>>
>> I was able to build the code successfully in both Eclipse and Netbeans.
>> However, I can only see "Hello world" but not "done" from the console
>> output.
>>
>> It seems that a problem occurred while calling the Rcpp function
>> CharacterVector::create, regardless of whether I had linked to Rcpp.dll.
>>
>> Does anyone has any idea what's happening here, or any idea on how to
>> effectively debug the C++ code for an R package within an C++ IDE? I
>>  actually had no problem calling the package in RStudio.
>>
>> Thanks!
>> Jing
>>
>>
>>
>> _______________________________________________
>> Rcpp-devel mailing list
>> Rcpp-devel at lists.r-forge.r-project.org
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>>
>
>
>
> --
> Qiang Kou
> qkou at umail.iu.edu
> School of Informatics and Computing, Indiana University
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140711/ef31eaee/attachment-0001.html>


More information about the Rcpp-devel mailing list