标题: AIX下多线程程序代码出错请教 [打印本页] 作者: JimmyWuMr 时间: 2005-10-21 14:56 标题: AIX下多线程程序代码出错请教 从Stevens大师UNIX Network Programming, Volume 2 IPC 一书中拷贝了一个多线程的程序代码,编译出错如下:
xlc -o ../prog/prodcons2 ../objs/prodcons2.o ../objs/error.o
ld: 0711-317 ERROR: Undefined symbol: .pthread_create
ld: 0711-317 ERROR: Undefined symbol: .pthread_join
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlocak
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
make: 1254-004 The error code from the last command is 8.
Stop.
实际上pthread_create, pthread_join, pthread_mutex_lock这几个函数在头文件pthread.h中都已经有了,man pthread_create有如下提示:
Note: The pthread.h header file must be the first included file of each source file using the threads library. Otherwise, the -D_THREAD_SAFE compilation flag should be used, or the cc_r compiler used. In this case, the flag is automatically set.
int nitems; /* read-only by producer and consumer */
struct{
pthread_mutex_t mutex;
int buff[MAXNITEMS];
int nput;
int nval;
} shared = {
PTHREAD_MUTEX_INITIALIZER
};
void *produce(void *), *consume(void *);
int
main(int argc, char ** argv)
{
int i, nthreads, count[MAXNTHREADS];
pthread_t tid_produce[MAXNTHREADS], tid_consume;