【问题标题】:Error building libpthreads-stubs-0.3 on Windows在 Windows 上构建 libpthreads-stubs-0.3 时出错
【发布时间】:2016-06-08 10:14:02
【问题描述】:

我正在尝试在具有 MinGW 和 MSys 环境的 Windows 机器上编译 libpthreads-stubs-0.3(用于 vaapi)。我已经在 MinGW 中安装了 mingw32-pthreads-w32 开发包(版本 2.9.1-1)。

现在当我尝试编译 libpthreads-stubs-0.3(只有一个名为 stubs.c 的文件)时,我得到一个类型冲突的错误:

make  all-am
make[1]: Entering directory `/c/Users/Pawan/Downloads/Compressed/libpthread-stubs-0.3/libpthread-stubs-0.3'
/bin/sh ./libtool --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.     -g -O2  -MT stubs.lo -MD -MP -MF .deps/stubs.Tpo -c -o stubs.lo stubs.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -g -O2  -MT stubs.lo -MD -MP -MF .deps/stubs.Tpo -c stubs.c  -DDLL_EXPORT -DPIC -o .libs/stubs.o

stubs.c:36:5: error: conflicting types for 'pthread_self'
 int pthread_self() __attribute__ ((weak, alias ("__pthread_zero_stub")));
     ^
In file included from stubs.c:29:0:
c:\mingw\include\pthread.h:955:37: note: previous declaration of 'pthread_self' was here
 PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void);
                                     ^

stubs.c:153:5: error: conflicting types for 'pthread_exit'
 int pthread_exit() __attribute__ ((weak, alias ("__pthread_exit_stub")));
     ^
In file included from stubs.c:29:0:
c:\mingw\include\pthread.h:950:32: note: previous declaration of 'pthread_exit' was here
 PTW32_DLLPORT void PTW32_CDECL pthread_exit (void *value_ptr);
                                ^
stubs.c:162:5: warning: 'pthread_equal' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
 int pthread_equal() __attribute__ ((weak, alias ("__pthread_equal_stub")));
     ^
stubs.c: In function '__pthread_equal_stub':
stubs.c:187:16: error: invalid operands to binary == (have 'pthread_t' and 'pthread_t')
     return (t1 == t2);
                ^
make[1]: *** [stubs.lo] Error 1
make[1]: Leaving directory `/c/Users/Pawan/Downloads/Compressed/libpthread-stubs-0.3/libpthread-stubs-0.3'
make: *** [all] Error 2

现在,当我在文件顶部注释 #include <pthread.h> 并将其放入 ifndef 时(因为如果我不这样做,我会收到错误:error: unknown type name 'pthread_t',这很明显)我会收到与上述相同的错误:

#ifdef NEED_EQUAL_STUB
#include <pthread.h>
static int __pthread_equal_stub(pthread_t t1, pthread_t t2)
{
    return (t1 == t2);
}
#endif

编辑: Stubs.c 文件代码

#define HAVE_STRUCT_TIMESPEC

//#include <pthread.h>
#include <stdlib.h>
#include "config.h"

#ifndef HAVE_PTHREAD_SELF
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_self() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
#  pragma weak pthread_self = __pthread_zero_stub
# endif
#endif

#ifndef HAVE_PTHREAD_MUTEX_INIT
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_mutex_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
#  pragma weak pthread_mutex_init = __pthread_zero_stub
# endif
#endif

#ifndef HAVE_PTHREAD_MUTEX_DESTROY
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_mutex_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
#  pragma weak pthread_mutex_destroy = __pthread_zero_stub
# endif
#endif

#ifndef HAVE_PTHREAD_MUTEX_LOCK
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_mutex_lock() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
#  pragma weak pthread_mutex_lock = __pthread_zero_stub
# endif
#endif

#ifndef HAVE_PTHREAD_MUTEX_UNLOCK
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_mutex_unlock() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
#  pragma weak pthread_mutex_unlock = __pthread_zero_stub
# endif
#endif

#ifndef HAVE_PTHREAD_COND_INIT
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
#  pragma weak pthread_cond_init = __pthread_zero_stub
# endif
#endif

#ifndef HAVE_PTHREAD_COND_DESTROY
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
#  pragma weak pthread_cond_destroy = __pthread_zero_stub
# endif
#endif

#ifndef HAVE_PTHREAD_CONDATTR_INIT
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_condattr_init() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
#  pragma weak pthread_condattr_init = __pthread_zero_stub
# endif
#endif

#ifndef HAVE_PTHREAD_CONDATTR_DESTROY
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_condattr_destroy() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
#  pragma weak pthread_condattr_destroy = __pthread_zero_stub
# endif
#endif

#ifndef HAVE_PTHREAD_COND_WAIT
#define NEED_ABORT_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_wait() __attribute__ ((weak, alias ("__pthread_abort_stub")));
# else
#  pragma weak pthread_cond_wait = __pthread_abort_stub
# endif
#endif

#ifndef HAVE_PTHREAD_COND_TIMEDWAIT
#define NEED_ABORT_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_timedwait() __attribute__ ((weak, alias ("__pthread_abort_stub")));
# else
#  pragma weak pthread_cond_timedwait = __pthread_abort_stub
# endif
#endif

#ifndef HAVE_PTHREAD_COND_SIGNAL
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_signal() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
#  pragma weak pthread_cond_signal = __pthread_zero_stub
# endif
#endif

#ifndef HAVE_PTHREAD_COND_BROADCAST
#define NEED_ZERO_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_cond_broadcast() __attribute__ ((weak, alias ("__pthread_zero_stub")));
# else
#  pragma weak pthread_cond_broadcast = __pthread_zero_stub
# endif
#endif

#ifndef HAVE_PTHREAD_EXIT
#define NEED_EXIT_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_exit() __attribute__ ((weak, alias ("__pthread_exit_stub")));
# else
#  pragma weak pthread_exit = __pthread_exit_stub
# endif
#endif

#ifndef HAVE_PTHREAD_EQUAL
#define NEED_EQUAL_STUB
# ifdef SUPPORT_ATTRIBUTE_ALIAS
int pthread_equal() __attribute__ ((weak, alias ("__pthread_equal_stub")));
# else
#  pragma weak pthread_equal = __pthread_equal_stub
# endif
#endif

#ifdef NEED_ZERO_STUB
static int __pthread_zero_stub()
{
    return 0;
}
#endif

#ifdef NEED_ABORT_STUB
static int __pthread_abort_stub()
{
    abort();
}
#endif

#ifdef NEED_EQUAL_STUB
//#define HAVE_STRUCT_TIMESPEC
#include <pthread.h>
static int __pthread_equal_stub(pthread_t t1, pthread_t t2)
{
    return (t1 == t2);
}
#endif

#ifdef NEED_EXIT_STUB
static void __pthread_exit_stub(void *ret)
{
    exit(EXIT_SUCCESS);
}
#endif

【问题讨论】:

  • 你能发布你的文件 stubs.c 吗?我遇到这种情况的唯一一次是当不同的文件在不同的位置包含不同的标题但名称相同时,但由于你只有一个文件,我认为不会是这样。
  • @mgarey 我已经添加了 stubs.c 文件。请看一看。

标签: mingw pthreads-win32 vaapi


【解决方案1】:

我无法重现您的错误,但(我认为)成功安装了 libpthreads-stubs-0.3。我正在使用 64 位版本的 msys 和 mingw。

我从 this website 下载了 libpthreads-stubs-0.3,使用 tar -xzf 将它解压缩到我在 msys 中的主文件夹,cd 到文件夹中,然后是 ./configure --prefix=/usr 然后是 make 然后是 make install .

我曾经拥有error: conflicting types for ...error: previous declaration for ...,这是因为我在一个地方包含了mingw 的pthreads.h,而在其他地方包含了用于Windows 的不同版本的pthreads.h。

如果一切都失败了,请尝试从头开始安装 mingw 和 libpthreads-stubs-0.3。

【讨论】:

    猜你喜欢
    • 2013-08-12
    • 2015-10-31
    • 2019-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 2016-04-26
    相关资源
    最近更新 更多