【发布时间】:2012-02-13 19:15:03
【问题描述】:
我有一个脚本可以在 Linux (Ubuntu 11.04) 上正常编译,但在 OS X (Lion) 上却不行。
gcc -pthread -o hw1 hw1.c
hw1.c:22: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘barr’
hw1.c: In function ‘__syncthreads’:
hw1.c:53: error: ‘barr’ undeclared (first use in this function)
hw1.c:53: error: (Each undeclared identifier is reported only once
hw1.c:53: error: for each function it appears in.)
hw1.c:54: error: ‘PTHREAD_BARRIER_SERIAL_THREAD’ undeclared (first use in this function)
hw1.c: In function ‘parallel_psum’:
hw1.c:94: error: ‘barr’ undeclared (first use in this function)
hw1.c:107: warning: assignment from incompatible pointer type
这是代码的前 22 行:
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <sys/time.h>
#include <pthread.h>
#include <assert.h>
/* create thread argument struct for thr_func() */
typedef struct _thread_data_t {
int tid;
int* ints;
int* sums;
int num_ints;
int* temp;
} thread_data_t;
const int MIN_RAND_INT = 1;
const int MAX_RAND_INT = 65000;
// pthreads barrier variable
pthread_barrier_t barr;
任何想法为什么会发生这种情况?
【问题讨论】:
-
好像没有定义pthread_barrier_t。
-
据我了解这是pthread库定义的类型
-
OSX 可能没有
pthred_barrier_t。 this question 中提到了一些关于此的提示 -
嗯,这说明了这一点。 Linux 的胜利 :) 谢谢
-
是的,OS X 似乎有点像 2001 年左右冻结的 POSIX。帮助人们编写符合现代标准的代码似乎并不是他们的首要目标。
标签: c macos gcc compiler-errors pthreads