Write a main() C++ function that creates an R instance using RInside, executes R code (or sources an R script) that sets up the test case, and then call the function under test from main(), e.g.#include <Rcpp.h>#include <RInside.h>#include "function_under_test.h"int main(int argc, char *argv[]){ using namespace std; using namespace Rcpp; RInside R(argc, argv); string evalstr = R"( a <- matrix(c(1,1,1, 1,1,1, 1,1,1), nrow = 3, ncol=3) )"; R.parseEvalQ(evalstr); SEXP a = R["a"]; R["b"] = function_under_test(a); evalstr = R"( print(b) )"; R.parseEvalQ(evalstr); return 0;}然后,通过在function_under_test()等中设置断点,使用gdb调试C ++程序时照常进行.Then proceed as usual when debugging a C++ program with gdb by setting breakpoints in function_under_test() etc.这样,您可以避免在R和C ++开发环境之间切换,而不必重新安装R软件包.This way you avoid switching between R and C++ development environments and having to re-install the R package. 这篇关于如何使用GDB在Emacs中调试R包(带有C代码)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-13 13:44