来自上一个声明的 G++ 错误,由于包含中的函数名称重复而导致的错误
G++ error from previous declaration, error due to duplicate function name in includes
我正在编写一个包含两个库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,文件是为不受支持的文件格式构建的",并在 .当我在 R 中加载后尝试时调用。我做错了什么?
也许脱离上下文,我正在使用 trng4 包来开发一个线程 gibbs 采样器(在 openmp 中),该采样器从伽马分布中采样。我目前正在运行这个MacOS。但最终它将在Linux服务器中运行。
听起来犰狳和trng4之间确实有问题。 如果可能的话,也许您应该尝试将接口分开,这样您就不需要在同一文件中包含两者。
如果我错了,有人可以纠正我,但我相信您可以通过在每个头文件中使用 #ifndef 来防止此问题,这样即使它第二次包含也不会第二次定义。但我想这些不是你的文件是吗...?
#ifndef __your_unique_header_name__
blah blah
#endif
相关文章:
- 链接器错误:函数的多个定义
- 编译器错误:函数调用在常量表达式中必须有一个常量值
- 错误:函数声明符之后的预期函数体
- C 错误 - 函数不能超载
- 如何修复传递参数时调用错误函数的主函数?(C++)
- 错误:函数调用中有两个参数
- 错误:函数不是“类”的静态数据成员 - C++
- C ,G 编译错误函数
- CMake 解析错误函数缺少结尾")"。而是找到带有文本的未终止字符串")
- C++ 错误 函数 2 的多重定义
- 错误:函数调用中从int到int(*)[4]的转换无效
- C++14 自动扣除错误:函数返回一个数组
- 视觉C++错误:函数必须返回一个值
- 错误:函数声明中的两种或多种数据类型
- 错误:函数未在作用域中声明
- rtw_android.c错误:函数“strnicmp”的隐式声明[-Weror=隐式函数声明]
- 错误:函数中的return语句没有值,返回“void*”[-fpermission]
- 简单程序中的链接器错误:函数的多重定义
- 错误:函数参数太多
- 错误:函数__tmaincrtstartup中引用的未解析的外部符号_main