c - C - 现有和已定义宏的冲突错误消息“隐式声明”和“嵌套外部声明”
问题描述
++=UPDATE 1=++ 使用 -E 运行返回以下内容:
# 100 "/usr/include/sys/byteorder.h" 3
#define BSWAP_64(x) (((uint64_t)(x) << 56) | (((uint64_t)(x) << 40) & 0xff000000000000ULL) | (((uint64_t)(x) << 24) & 0xff0000000000ULL) | (((uint64_t)(x) << 8) & 0xff00000000ULL) | (((uint64_t)(x) >> 8) & 0xff000000ULL) | (((uint64_t)(x) >> 24) & 0xff0000ULL) | (((uint64_t)(x) >> 40) & 0xff00ULL) | ((uint64_t)(x) >> 56))
...
#define _LP64 1
...
# 86 "LALCityHash.c" 2
#define bswap_32(x) BSWAP_32(x)
#define bswap_64(x) BSWAP_64(x)
# 117 "LALCityHash.c"
#define UINT4_in_expected_order(x) (bswap_32(x))
#define UINT8_in_expected_order(x) (bswap_64(x))
它似乎通过了CPP。
完整内容在https://pastebin.com/u6VU9sie
LALCityHash.c 来源https://pastebin.com/GfQ3CxBX
--=更新 1=-
我正在为 SPARC/Solaris 编译 LIGO 软件包并遇到错误。LALCityHash.c 为 BSWAP_64 提供了一个别名,它似乎没有通过未修改代码中提供的必要#includes 获得通过。
我试图看看在其他地方重新定义定义是否有帮助,以防“#if defined(__sun) || defined(sun)”行没有被解析。即使剥离 .h 包括在文件本地使用所需的代码也不起作用。我只是无法弄清楚我在忽略什么。
LALCityHash.c 包括以下几行:
#elif defined(__sun) || defined(sun)
#define bswap_32(x) BSWAP_32(x)
:87 => #define bswap_64(x) BSWAP_64(x) <=
...
:118 => #define UINT8_in_expected_order(x) (bswap_64(x)) <=
...
static UINT8 Fetch64(const char *p) {
:133 => return UINT8_in_expected_order(UNALIGNED_LOAD64(p)); <=
}
产生以下两个错误:
函数“ BSWAP_64 ”的隐式声明' BSWAP_64 ' 的 嵌套外部声明
Solaris 的操作系统包含文件是 sys/byteorder.h,定义如下:
#if defined(_LP64) || defined(_LONGLONG_TYPE)
#if (!defined(__i386) && !defined(__amd64))
#define BSWAP_64(x) (((uint64_t)(x) << 56) | \
(((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
(((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
(((uint64_t)(x) << 8) & 0xff00000000ULL) | \
(((uint64_t)(x) >> 8) & 0xff000000ULL) | \
(((uint64_t)(x) >> 24) & 0xff0000ULL) | \
(((uint64_t)(x) >> 40) & 0xff00ULL) | \
((uint64_t)(x) >> 56))
#else /* x86 */
#define BSWAP_64(x) htonll(x)
#endif /* !__i386 && !__amd64 */
#else /* no uint64_t */
#define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
#endif /* _LP64 || _LONGLONG_TYPE */
尽在公用事业中 gmake[4]:进入目录'/export/home/tidytibs/ligo/lal-6.19.2/src/utilities' CC LALCityHash.lo LALCityHash.c:在函数“ Fetch64 ”中: LALCityHash.c:87:21: 错误:函数“ BSWAP_64 ”的隐式声明 [ -Werror=implicit-function-declaration ] #define bswap_64(x) B SWAP_64(x) ^ LALCityHash.c:118:37: 注意:在宏“ bswap_64 ”的扩展中 #define UINT8_in_expected_order(x) ( bswap_64 (x)) ^~~~~~~~ LALCityHash.c:133:10: 注意:在宏' UINT8_in_expected_order '的扩展中 返回UINT8_in_expected_order (UNALIGNED_LOAD64(p)); ^~~~~~~~~~~~~~~~~~~~~~~ LALCityHash.c:87:21: 错误: ' BSWAP_64 '的嵌套外部声明[ -Werror=nested-externs ] #define bswap_64(x) B SWAP_64(x) ^ LALCityHash.c:118:37: 注意:在宏“ bswap_64 ”的扩展中 #define UINT8_in_expected_order(x) ( bswap_64 (x)) ^~~~~~~~ LALCityHash.c:133:10: 注意:在宏' UINT8_in_expected_order '的扩展中 返回UINT8_in_expected_order (UNALIGNED_LOAD64(p)); ^~~~~~~~~~~~~~~~~~~~~~~ LALCityHash.c:在函数' Fetch32 '中: LALCityHash.c:86:21: 错误:函数' BSWAP_32 '的隐式声明[ -Werror=隐式函数声明] #define bswap_32(x) B SWAP_32(x) ^ LALCityHash.c:117:37: 注意:在宏“ bswap_32 ”的扩展中 #define UINT4_in_expected_order(x) ( bswap_32 (x)) ^~~~~~~~ LALCityHash.c:137:10: 注意:在宏' UINT4_in_expected_order '的扩展中 返回UINT4_in_expected_order (UNALIGNED_LOAD32(p)); ^~~~~~~~~~~~~~~~~~~~~~~ LALCityHash.c:86:21: 错误: ' BSWAP_32 '的嵌套外部声明[ -Werror=nested-externs ] #define bswap_32(x) B SWAP_32(x) ^ LALCityHash.c:117:37: 注意:在宏“ bswap_32 ”的扩展中 #define UINT4_in_expected_order(x) ( bswap_32 (x)) ^~~~~~~~ LALCityHash.c:137:10: 注意:在宏' UINT4_in_expected_order '的扩展中 返回UINT4_in_expected_order (UNALIGNED_LOAD32(p)); ^~~~~~~~~~~~~~~~~~~~~~~ cc1:所有警告都被视为错误 gmake[4]: *** [Makefile:586: LALCityHash.lo] 错误 1
解决方案
已解决:似乎 LALCityHash.c 包含 Solaris sys/byteorder.h,其中定义了
#define BSWAP_32(x) (((uint32_t)(x) << 24) | (((uint32_t)(x) << 8) & 0xff0000) | (((uint32_t)(x) >> 8) & 0xff00) | ((uint32_t)(x) >> 24))
#define BSWAP_64(x) (((uint64_t)(x) << 56) | (((uint64_t)(x) << 40) & 0xff000000000000ULL) | (((uint64_t)(x) << 24) & 0xff0000000000ULL) | (((uint64_t)(x) << 8) & 0xff00000000ULL) | (((uint64_t)(x) >> 8) & 0xff000000ULL) | (((uint64_t)(x) >> 24) & 0xff0000ULL) | (((uint64_t)(x) >> 40) & 0xff00ULL) | ((uint64_t)(x) >> 56))
并将另一个定义为别名
# 86 "LALCityHash.c" 2
#define bswap_32(x) BSWAP_32(x)
#define bswap_64(x) BSWAP_64(x)
这里的建筑不喜欢这样。
相反,用sys/byteorder.h的 "BSWAP_32/64" 定义替换LALCityHash.c " bswap_32/64" 定义有效:
86,87c86,97
< #define bswap_32(x) BSWAP_32(x)
< #define bswap_64(x) BSWAP_64(x)
---
> #define bswap_32(x) (((uint32_t)(x) << 24) | \
> (((uint32_t)(x) << 8) & 0xff0000) | \
> (((uint32_t)(x) >> 8) & 0xff00) | \
> ((uint32_t)(x) >> 24))
> #define bswap_64(x) (((uint64_t)(x) << 56) | \
> (((uint64_t)(x) << 40) & 0xff000000000000ULL) | \
> (((uint64_t)(x) << 24) & 0xff0000000000ULL) | \
> (((uint64_t)(x) << 8) & 0xff00000000ULL) | \
> (((uint64_t)(x) >> 8) & 0xff000000ULL) | \
> (((uint64_t)(x) >> 24) & 0xff0000ULL) | \
> (((uint64_t)(x) >> 40) & 0xff00ULL) | \
> ((uint64_t)(x) >> 56))
我仍然看不到#define 的有效#define 别名在这里不起作用。
推荐阅读
- php - 由于 Web.config 文件,Robots.txt 文件未显示
- python - 如何使用 Python 和 Regex 搜索特定字符串
- python - 比较 pandas 中的两列。如何检查哪一行不同?
- android - 如何将 Android Gradient Drawable (XML) 转换为 Flutter Gradient?
- python - 查找数据框中某行的最大值的列名
- powershell - 为什么从角色成员中删除不起作用?
- continuous-integration - 如何使用 vsts-ci.yml 在 Azure DevOps CI/CD 管道中运行 cypress 测试
- r - 将字符串转换为对象 - 但转换为实际文本,未评估
- asp.net-core - ASP.NET Core 2 MVC CheckBoxFor 在模型中总是返回 false
- python - Py - 使用输入打印数组的数据