c++ - 先前声明的 G++ 错误,由于 include 中的函数名称重复而导致错误

标签 c++ gcc compilation openmp rcpp

我正在编写包含两个库 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/

相关文章:

c++ - 错误 : name lookup of 'i' changed for ISO 'for' scoping

c++ - 递归类型的模板特化

iphone - 使用 Go 为 iPhone 应用程序编写库

java - 用于从 C 生成数据绑定(bind)的开源解析器?

c++ - 使用 ncurses 时未定义对 `stdscr' 的引用

c++ - 如何在不使用 cygwin 的情况下在 Windows (Vista) 中为 C++ 文件运行 makefile?

android - 如何在 Android NDK 中使用 Asio(独立于 Boost)?

c++ - FFmpeg Ubuntu 链接器错误

linux - 如何更改 gcc 生成的 asm 代码的入口点?

java - Fedora 25 - 拒绝识别 Java JDK,$JAVA_HOME 似乎是正确的