gpt4 book ai didi

gcc - 为什么 GCC 提示 'sizeof' 之前缺少不存在的标识符?

转载 作者:行者123 更新时间:2023-12-03 02:28:10 28 4
gpt4 key购买 nike

我正在为 Windows 交叉编译 GTK+ 3.4.4。我已经交叉编译了 GTK 的所有构建依赖项(ATK、Cairo、GDK Pixbuf 和 Pango)并将它们安装到 /usr/i686-w64-mingw32/ .

但是,尝试编译 GTK 本身会导致以下错误:

In file included from gdkrgba.c:31:0:
fallback-c89.c:40:1: error: expected identifier or '(' before 'sizeof'
fallback-c89.c:40:1: error: expected ')' before '==' token

gdk/fallback-c89.c 第 34 - 44 行包含:

34.  #ifndef HAVE_ISINF
35. /* Unfortunately MSVC does not have finite()
36. * but it does have _finite() which is the same
37. * as finite() except when x is a NaN
38. */
39. static inline gboolean
40. isinf (double x)
41. {
42. return (!_finite (x) && !_isnan (x));
43. }
44. #endif

我一点也不知道 GCC 在哪里找到 'sizeof '或'== '。为什么编译器会抛出如此神秘的错误消息以及如何修复它?

<小时/>

编辑:这是实际的命令行:

/usr/bin/i686-w64-mingw32-gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I..
-DG_LOG_DOMAIN="Gdk" -DGDK_COMPILATION -I.. -I../gdk -I..
-DG_DISABLE_CAST_CHECKS -mms-bitfields
-I/usr/i686-w64-mingw32/include/pango-1.0
-I/usr/i686-w64-mingw32/include/glib-2.0
-I/usr/i686-w64-mingw32/lib/glib-2.0/include
-I/usr/i686-w64-mingw32/include/cairo -I/usr/i686-w64-mingw32/include/pixman-1
-I/usr/i686-w64-mingw32/include -I/usr/i686-w64-mingw32/include/freetype2
-I/usr/i686-w64-mingw32/include/libpng15
-I/usr/i686-w64-mingw32/include/gdk-pixbuf-2.0 -O2 -Wall -mms-bitfields -MT
gdkrgba.lo -MD -MP -MF .deps/gdkrgba.Tpo -c gdkrgba.c -DDLL_EXPORT -DPIC -o
.libs/gdkrgba.o
<小时/>

进一步编辑:使用-E编译后选项,我捕获了以下预处理输出...这解释了奇怪的 sizeof :

# 39 "fallback-c89.c"
static inline gboolean
((sizeof (double x) == sizeof (float) ? __fpclassifyf (double x) : sizeof double x)) == (0x0100 | 0x0400))
{
return (!_finite (x) && !_isnan (x));
}

我只能得出结论:isinf已经是一个已定义的宏。它只是在上面的函数声明中使用时被扩展。

我的问题现在变成了...为什么是 HAVE_ISINF没有定义的?是配置脚本的问题吗?

<小时/>

另一个编辑:好的,所以我决定在构建树中搜索包含字符串“HAVE_ISINF”的所有内容。 '并遇到以下情况:

  • autom4te.cache/traces.1

    m4trace:configure.ac:740: -1- AH_OUTPUT([HAVE_ISINF], [/* Define to 1 if you
    have the `isinf\' function. */
    @%:@undef HAVE_ISINF])
  • config.h.in

    /* Define to 1 if you have the `isinf' function. */
    #undef HAVE_ISINF
  • config.h

    /* Define to 1 if you have the `isinf' function. */
    /* #undef HAVE_ISINF */

令人惊讶的是,config.log 中什么也没有。提及“HAVE_ISINF”。

<小时/>

(可能)最终编辑:我做了更多调查,并在 autom4te.cache/output.0 中找到了字符串“isinf”这里:http://paste.ubuntu.com/1154478/

此代码引用了ac_fn_c_check_func ,所以我挖出了source for that function并编译the .c sample that the script generates :

test.c:25:6: warning: conflicting types for built-in function ‘isinf’
[enabled by default]
/tmp/ccLYd1R8.o:test.c:(.text+0xc): undefined reference to `_isinf'
collect2: ld returned 1 exit status

这很奇怪,因为我上面的解释表明 isinf只是一个宏。

最佳答案

我终于找到了this 。总结一下:

"The isnan() and isinf() are C99 macros not functions so use AC_CHECK_DECL instead of AC_CHECK_FUNCS for those."

看来我要修补源代码了。

关于gcc - 为什么 GCC 提示 'sizeof' 之前缺少不存在的标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12022263/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com