【问题标题】:glib.h negative array size error in 64 bit but not 32 bit buildglib.h 64 位但不是 32 位构建中的负数组大小错误
【发布时间】:2014-07-02 21:17:01
【问题描述】:

我在一个开发环境中工作,我们同时生产 32 位和 64 位 可执行文件。我有一个无法以 64 位模式构建的应用程序。 它使用 inotify 并包含 glib.h 来获取它的定义。

我决定看看一个最小的程序是否会导致问题发生,就在这里。

测试源glibtest.c:

    #include <stdio.h>
    #include <glib.h>

    int
    main (int argc, char ** argv)
    {
        printf( "hello, I am glib test.\n\n");
    }

在 32 位模式下构建...

    [svn/glibtest] : gcc glibtest.c -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -m32
    [svn/glibtest] : a.out
    hello, I am glib test.

    [svn/glibtest] :

事物以 32 位模式编译,a.out 打印出预期的内容。 现在如果在 64 位模式下编译就会出现错误。

    [svn/glibtest] : gcc  -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include glibtest.c
    In file included from /usr/include/glib-2.0/glib/gasyncqueue.h:34,
                     from /usr/include/glib-2.0/glib.h:34,
                     from glibtest.c:7:
    /usr/include/glib-2.0/glib/gthread.h: In function ‘g_once_init_enter’:
    /usr/include/glib-2.0/glib/gthread.h:347: error: size of array ‘type name’ is negative
    [svn/glibtest] :

在 64 位模式下,错误指向 gthread.h 这里...

    #if defined (G_CAN_INLINE) || defined (__G_THREAD_C__)
    G_INLINE_FUNC gboolean
    g_once_init_enter (volatile gsize *value_location)
    {
    error>>>  if G_LIKELY ((gpointer) g_atomic_pointer_get (value_location) != NULL)
        return FALSE;
      else
        return g_once_init_enter_impl (value_location);
    }
    #endif /* G_CAN_INLINE || __G_THREAD_C__ */

我是否缺少所需的标题?有没有人见过这个并找到解决方案? (是的,一年前有一个类似的帖子没有人回答。)

Centos 6.5,'Linux tushar 2.6.32-431.17.1.el6.x86_64 #1 SMP Wed May 7 23:32:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux' glib 包是 1:1.2.10-33.el6
gcc (GCC) 4.4.7 20120313 (红帽 4.4.7-4)

谢谢。

【问题讨论】:

  • 你看过预处理的源码吗?即-E gcc 选项
  • 你好像用的是旧版本,你能安装更新版本的glib吗?

标签: c linux gcc


【解决方案1】:

/usr/lib/glib-2.0/include 通常是特定于平台的。它可能包含 32 位特定的定义。例如,我在 /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h 中有以下内容:

#define GLIB_SIZEOF_SIZE_T 8

在您的版本中可能是 4,因为它似乎是 32 位的。

【讨论】:

    【解决方案2】:

    检查您是否有正确的 glibconfig.h 文件包含在您的构建目标(64 位)的正确设置中。对于不同的目标(32 位和 64 位),您必须有不同的 glibconfig.h

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-13
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 2019-03-19
      相关资源
      最近更新 更多