Gcc Pthreads编译不工作
我已经写了一些代码,但当我编译它时,它似乎不起作用。我试图在Ubuntu中运行此功能:Gcc Pthreads编译不工作,gcc,pthreads,Gcc,Pthreads,我已经写了一些代码,但当我编译它时,它似乎不起作用。我试图在Ubuntu中运行此功能: #include <pthread.h> #include <ctype.h> #include <unistd.h> char buffer[128]; void *write_thread(void *args) { int count = *((int*)args); write(STDOUT_FILENO, buffer, count);
#include <pthread.h>
#include <ctype.h>
#include <unistd.h>
char buffer[128];
void *write_thread(void *args)
{
int count = *((int*)args);
write(STDOUT_FILENO, buffer, count);
pthread_exit(0);
}
void *toupper_thread(void *args)
{
int i;
int count = *((int*)args);
for(i = 0; i < count; i++) {
buffer[i] = toupper(buffer[i]);
}
pthread_t writeId;
pthread_create(&writeId, NULL, write_thread, &count);
pthread_join(writeId, NULL);
pthread_exit(0);
}
void *read_thread(void *args)
{
int count = read(STDIN_FILENO, buffer, 128);
pthread_t toupperId;
pthread_create(&toupperId, NULL, toupper_thread, &count);
pthread_join(toupperId, NULL);
//buffer[count] = 0;
pthread_exit(0);
}
int main()
{
pthread_t threadId;
pthread_create(&threadId, NULL, read_thread, NULL);
pthread_join(threadId, NULL);
}
我不知道我做错了什么。需要在compile命令中添加-I标志以使编译器能够找到pthread.h需要在compile命令中添加-I标志以使编译器能够找到pthread.h看起来您遗漏了一些依赖项 试试这个:
$ sudo apt-get install -y libc6-dev
您似乎遗漏了一些依赖项 试试这个:
$ sudo apt-get install -y libc6-dev
- 系统中没有pthread.h库。尝试安装 适合它的图书馆
- 您需要确保使用
#include
- 编译时不要忘记添加-lpthread:
gcc-lpthread{x}.c-o{y}
- 系统中没有pthread.h库。尝试安装 适合它的图书馆
- 您需要确保使用
#include
- 编译时不要忘记添加-lpthread:
gcc-lpthread{x}.c-o{y}