linux使用线程函数时报错

调用的pthread函数未被应用

warning: implicit declaration of function ‘pthread_create’; did you mean ‘timer_create’? [-Wimplicit-function-declaration] pthread_create(\&t1,NULL,refreshJieMian,NULL);

先检查头文件有没有定义

#include 

再检查编译时是否链接好了线程库如

gcc a.c -lpthread

如果都没问题的话,看这篇博客

编译报错函数成员类型警告

把“void *sayhello(void *arg)”改成“void sayhello(void *arg)”会报错如下:

root@book-desktop:/opt/pc_test/multithreading/1# make

gcc -o main main.c -lpthread

main.c: In function ‘main’:

main.c:14: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type

/usr/include/pthread.h:227: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(void *)’

把“void *sayhello(void *arg)”改成“void *sayhello(void)”会报错如下:

root@book-desktop:/opt/pc_test/multithreading/1# make

gcc -o main main.c -lpthread

main.c: In function ‘main’:

main.c:14: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type

/usr/include/pthread.h:227: note: expected ‘void * (*)(void *)’ but argument is of type ‘void * (*)(void)’

而且有些编译器括号中的void * 型写成void 型也会报该错误,需要将(void)改成(void *arg)

你可能感兴趣的:(错误debug,linux学习,linux,c)