Scheme 将guile链接到Rcpp

Scheme 将guile链接到Rcpp,scheme,rcpp,guile,Scheme,Rcpp,Guile,我正在尝试将guile链接到Rcpp文件。看起来像是在编译,但加载时出现错误: sourceCpp("test_2.cpp", rebuild = TRUE, showOutput = TRUE) /usr/lib/R/bin/R CMD SHLIB --preclean -o 'sourceCpp_2.so' 'test_2.cpp' g++-10 -I"/usr/share/R/include" -DNDEBUG -I"/home/ma

我正在尝试将guile链接到Rcpp文件。看起来像是在编译,但加载时出现错误:

sourceCpp("test_2.cpp", rebuild = TRUE, showOutput = TRUE)
/usr/lib/R/bin/R CMD SHLIB --preclean -o 'sourceCpp_2.so' 'test_2.cpp' 
g++-10 -I"/usr/share/R/include" -DNDEBUG   -I"/home/matias/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include" -I"/home/matias/Documentos/Program/R/guile"    -fpic  -O3 -march=native -mtune=native -fPIC -pthread  -I"/usr/include/guile/3.0" -c test_2.cpp -o test_2.o
g++-10 -shared -L/usr/lib/R/lib -lm -ldl -lgmpxx -lgmp -lmpfr -lmpc -lguile-3.0 -lgc -o sourceCpp_2.so test_2.o -L/usr/lib/R/lib -lR
Error in dyn.load("/tmp/Rtmpm2flY8/sourceCpp-x86_64-pc-linux-gnu-1.0.5/sourcecpp_29e2d33505085/sourceCpp_2.so") : 
  unable to load shared object '/tmp/Rtmpm2flY8/sourceCpp-x86_64-pc-linux-gnu-1.0.5/sourcecpp_29e2d33505085/sourceCpp_2.so':
  /tmp/Rtmpm2flY8/sourceCpp-x86_64-pc-linux-gnu-1.0.5/sourcecpp_29e2d33505085/sourceCpp_2.so: undefined symbol: scm_init_guile
如果我删除Rcpp头并直接用g++构建,链接就可以正常工作

我的Makevar看起来像这样:

CXX = g++-10
CXXFLAGS = -O3 -march=native -mtune=native -fPIC -pthread  -I"/usr/include/guile/3.0"
CXXSTD = -std=c++11
LDFLAGS =  -lm -ldl -lgmpxx -lgmp -lmpfr -lmpc -lguile-3.0 -lgc
.cpp文件:

#include <Rcpp.h>
#include <stdio.h>
#include <libguile.h>

using namespace Rcpp;

// [[Rcpp::export]]
int test_guile() {
    SCM func, func2;
    scm_init_guile();

    scm_c_primitive_load("script.scm");

    func = scm_variable_ref(scm_c_lookup("simple-func"));
    func2 = scm_variable_ref(scm_c_lookup("quick-test"));

    scm_call_0(func);
    scm_call_0(func2);

    return 0;
}
#包括
#包括
#包括
使用名称空间Rcpp;
//[[Rcpp::导出]]
int test_guile(){
SCM func,func2;
scm_init_guile();
scm_c_原语_加载(“script.scm”);
func=scm_变量_ref(scm_c_查找(“简单func”));
func2=scm_变量_ref(scm_c_查找(“快速测试”);
scm_调用_0(func);
scm_调用_0(函数2);
返回0;
}

你真是太接近了。你基本上解决了这个问题。我只是拿了你的文件,对脚本做了一个小小的修改,使其成为一个参数,并且(因为你没有发布
script.scm
)注释掉了特定于内容的内容。但我们仍然加载它:

现在,它可以正常构建、安装和运行:

> file <- system.file("guile", "script.scm", package="RcppGuile")
> RcppGuile::test_guile(file)
[1] 0
> 

很好,很好。这是个很好的问题。我将答案写在Rcpp画廊的一篇短文中:
PKG_CXXFLAGS = -I"/usr/include/guile/3.0"
PKG_LIBS = -lguile-3.0 -lgc
> file <- system.file("guile", "script.scm", package="RcppGuile")
> RcppGuile::test_guile(file)
[1] 0
> 
> library(RcppGuile)
> test_guile(system.file("guile", "script.scm", package="RcppGuile"))
Script called, now I can change this
Adding another function, can modify without recompilation
Called this, without recompiling the C code
[1] 0
>