glib.h负数组大小错误64位但不是32位构建

时间:2014-07-02 21:17:02

标签: c linux gcc

我在开发环境中工作,我们生产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 5月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(Red Hat 4.4.7-4)

感谢。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

/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位的。