gpt4 book ai didi

c++ - 在 R 中执行 C++ 代码

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:05:27 25 4
gpt4 key购买 nike

我正在尝试使用 R 中的 boost 库执行 c++ 函数。我还安装了 boost 头文件包 (BH)。当我尝试执行代码时,出现以下错误:

src <- '
#include <Rcpp.h>
#include <boost/math/special_functions/binomial.hpp>
for (unsigned long i = 0; i < 5; ++i) {
boost::math::binomial_coefficient<double>(25, i);
}'
sillyExp <- cfunction(signature(), src, convention = ".C")

我哪里错了?

编辑:错误如下

Error in compileCode(f, code, language, verbose) : 
  Compilation ERROR, function(s)/method(s) not created! file68b0697546bd.cpp:11:54: fatal error: boost/math/special_functions/binomial.hpp: No such file or directory
 #include <boost/math/special_functions/binomial.hpp> 
                                                      ^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-34~1.3/etc/x64/Makeconf:215: file68b0697546bd.o] Error 1
Warning message:
running command 'make -f "C:/PROGRA~1/R/R-34~1.3/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-34~1.3/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file68b0697546bd.dll" WIN=64 TCLBIN=64 OBJECTS="file68b0697546bd.o"' had status 2 

最佳答案

如果你真的想执行一些C++代码,那么你可以使用Rcpp::evalCpp:

Rcpp::evalCpp("boost::math::binomial_coefficient<double>(25, 3)", 
depends="BH",
include="#include <boost/math/special_functions/binomial.hpp>")
#> [1] 2300

关于c++ - 在 R 中执行 C++ 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51174670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com