的Pthread和OS X的gcc编译问题 [英] Pthread and gcc compiling issue on OS X
问题描述
我已经编译在Linux(Ubuntu的11.04)的罚款的脚本,但不能在OS X(狮子)。
-pthread的gcc -o HW1 hw1.c
hw1.c:22:错误:预期'=',',',',','巴尔'前'ASM'或'__attribute__'
hw1.c:在函数'__syncthreads:
hw1.c:53:错误:'巴尔'未声明(第一次使用此功能使用)
hw1.c:53:错误:(每个未声明的标识符报道只有一次
hw1.c:53:错误:它出现在每个功能)
hw1.c:54:错误:'PTHREAD_BARRIER_SERIAL_THREAD'未申报(在一次使用此功能)
hw1.c:在函数'parallel_psum:
hw1.c:94:错误:'巴尔'未声明(第一次使用此功能使用)
hw1.c:107:警告:分配从兼容的指针类型
这里的code第一次22行:
的#include<&stdlib.h中GT;
#包括LT&;&stdio.h中GT;
#包括LT&;&time.h中GT;
#包括LT&;&math.h中GT;
#包括LT&; SYS / time.h中>
#包括LT&;&pthreads.h中GT;
#包括LT&;&ASSERT.H GT;/ *创建thr_func线程参数结构()* /
typedef结构_thread_data_t {
INT TID;
INT *整数;
INT *款项;
INT num_ints;
INT *温度;
} thread_data_t;const int的MIN_RAND_INT = 1;
const int的MAX_RAND_INT = 65000;// pthreads的屏障变量
pthread_barrier_t巴尔;
任何想法,为什么发生这种情况?
根据信息关于pthread_barriers 一>上opengroup.org,障碍在定义的可选的POSIX标准的一部分;选项的名称是(先进的实时线程)的,有时更精确称为BAR,障碍(实时)。
<一个href=\"http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap02.html\">http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap02.html
该系统可以支持一个或多个选项(参见选项)由下列符号常量表示:
块引用>_POSIX_BARRIERS
所以,只有当_POSIX_BARRIERS宏定义为正数,则可以使用pthread_barrier_t或pthread_barrier_wait。
的Mac OS X是POSIX兼容的,但实现的选项的完整列表不是可在网上。 有苹果米林县列表中的信从2006年,它说有没有障碍在Mac OS X。
我知道的Solaris有一些问题pthread_barrier了。
I have a script that compiles fine on Linux (Ubuntu 11.04), but not on 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
Here's the first 22 lines of the code:
#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;
Any ideas why this is happening?
解决方案According to info about pthread_barriers on opengroup.org, barriers are defined in the optional part of POSIX standard; the name of option is "(ADVANCED REALTIME THREADS)", sometimes more exact referred as "BAR, barriers (real-time)".
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap02.html
The system may support one or more options (see Options) denoted by the following symbolic constants:
_POSIX_BARRIERS
So, only if the _POSIX_BARRIERS macro is defined as positive number, you can use pthread_barrier_t or pthread_barrier_wait.
Mac OS X is POSIX Compliant, but full list of implemented options is not available online. There is a letter in apple mainling list from 2006, which says there is no barriers in Mac OS X.
I know that Solaris had some problems with pthread_barrier too.
这篇关于的Pthread和OS X的gcc编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!