我安装了R以及RStudio和RTools,目前我正试图让Rcpp运行。我尝试将此代码作为测试文件:
#include <RcppArmadillo.h>
#include <cmath.h>
//[[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
// [[Rcpp::export]]
double Mutual_Information(
arma::mat joint_dist
){
joint_dist = joint_dist/sum(sum(joint_dist));
double mutual_information = 0;
int num_rows = joint_dist.n_rows;
int num_cols = joint_dist.n_cols;
arma::mat colsums = sum(joint_dist,0);
arma::mat rowsums = sum(joint_dist,1);
for(int i = 0; i < num_rows; ++i){
for(int j = 0; j < num_cols; ++j){
double temp = log((joint_dist(i,j)/(colsums[j]*rowsums[i])));
if(!std::isfinite(temp)){
temp = 0;
}
mutual_information += joint_dist(i,j) * temp;
}
}
return mutual_information;
}
但我收到此错误消息:
c:/ Rtools / mingw_64 / bin / g ++ -std = gnu ++ 11 -I“C:/PROGRA~1/R/R-34~1.2/include”-DNDEBUG -I ../ inst / include -fopenmp -I“C:/ Users / root / Documents / R / win-library / 3.4 / Rcpp / include“-I”C:/Users/root/Documents/R/win-library/3.4/RcppArmadillo/include“-I”C:/ Users / root / OneDrive / Uni / SEMEST~1 / PROJEK~ 1 / test / src“-I”C:/ Users / root / OneDrive / Uni / Semester 3 / Projektarbeit / test / inst / include“
-I“d:/Compiler/gcc-4.9.3/local330/include”-O2 -Wall -mtune = core2 -c rcpp_hello_world.cpp -o rcpp_hello_world.o rcpp_hello_world.cpp:2:19:致命错误: cmath.h:没有这样的文件或 目录#include ^编译终止。 make:*** [rcpp_hello_world.o]
错误1 Warnmeldung:AusführungvonKommando 'make -f“C:/PROGRA~1/R/R-34~1.2/etc/x64/Makeconf”-f “C:/PROGRA~1/R/R-34~1.2/share/make/winshlib.mk”CXX ='$(CXX11) $(CXX11STD)'CXXFLAGS ='$(CXX11FLAGS)'CXXPICFLAGS ='$(CXX11PICFLAGS)' SHLIB_LDFLAGS ='$(SHLIB_CXX11LDFLAGS)'SHLIB_LD ='$(SHLIB_CXX11LD)' SHLIB =“sourceCpp_3.dll”WIN = 64 TCLBIN = 64 OBJECTS =“rcpp_hello_world.o”' Rcpp :: sourceCpp中的ergab状态2错误(“src / rcpp_hello_world.cpp”): 构建共享库时出现错误1。另外:警告 message:在normalizePath(path.expand(path),winslash,mustWork)中:
路径[1] =“C:/用户/根/ OneDrive / UNI /学期 3 / Projektarbeit / test / src /../ inst / include“:Das System kann den angegebenen Pfad nicht finden
库(“Rcpp”)和库(“RcppArmadillo”)已成功加载...
因此,我理解此错误后无法找到包含文件。编译器正在查找的路径不存在。它应该处理包含路径本身我假设.. 在QT或Visual Studio中包含此头文件可以正常工作..
我是否需要调整一些PATH设置?我在Windows 10 x64上运行它 我找不到使用谷歌的任何解决方案,所以我希望你能帮助我。 非常感谢
答案 0 :(得分:2)
错误消息中没有标头cmath.h
。你可能意味着cmath
。
修复和简化(无需命名空间声明)文件传递:
#include <RcppArmadillo.h>
#include <cmath>
//[[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
double Mutual_Information(arma::mat joint_dist){
joint_dist = joint_dist/sum(sum(joint_dist));
double mutual_information = 0;
int num_rows = joint_dist.n_rows;
int num_cols = joint_dist.n_cols;
arma::mat colsums = sum(joint_dist,0);
arma::mat rowsums = sum(joint_dist,1);
for(int i = 0; i < num_rows; ++i){
for(int j = 0; j < num_cols; ++j){
double temp = log((joint_dist(i,j)/(colsums[j]*rowsums[i])));
if(!std::isfinite(temp)){
temp = 0;
}
mutual_information += joint_dist(i,j) * temp;
}
}
return mutual_information;
}
即
R> sourceCpp("/tmp/soQ.cpp")
R>
这里没有错误。