我正在编写包含两个库 RcppArmadillo 和 trng4 的 Rcpp 代码。但是,当我包含两个头文件(RcppArmadillo.h 和 trng/gamma_dist.hpp)时,会出现编译错误。
trng/special_functions.hpp:47:39: error: declaration of ‘float lgammaf(float) throw ()’ has a different exception specifier
extern "C" float lgammaf(float) throw();
include-fixed/math.h:476:14: error: from previous declaration ‘float lgammaf(float)’
extern float lgammaf(float);
完整的编译选项是
-fopenmp -lgomp -DUSE_R -DNDEBUG -DDISABLE_SINGLE -DNTHROW -DDISABLE_FIO -I/usr/local/include -I"/Users/avi/Library/R/3.0/library/Rcpp/include" -I"/Users/avi/Library/R/3.0/library/RcppArmadillo/include" -fPIC -pipe -std=c++0x -Wall -pedantic -c
两个头文件中似乎都声明了 lgammaf。我尝试将 -E 与 g++ 选项一起使用,但给出了 ld 警告“.o,文件是为不受支持的文件格式构建的”,并给出错误函数在 .Call 中不可用,当我在 R 中加载后尝试它时。我做错了什么?
也许脱离了上下文,我正在使用 trng4 包开发一个线程 gibbs 采样器(在 openmp 中),它从 Gamma 分布中采样。我目前正在运行这个 MacOS。但最终它将在 linux 服务器上运行。
最佳答案
听起来您在 Armadillo 和 trng4 之间确实存在问题。如果可能的话,也许您应该尝试将您的界面分开,这样您就不需要将两者包含在同一个文件中。
关于c++ - 先前声明的 G++ 错误,由于 include 中的函数名称重复而导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21788791/