Gcc Pthreads编译不工作

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);

我已经写了一些代码,但当我编译它时,它似乎不起作用。我试图在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);

    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}

      您安装了libc6 dev吗?您安装了libc6 dev吗?我尝试了它,结果是:0升级,0新安装,0删除,33未升级。还可以尝试以下操作:sudo apt get install build essentialIn在这种情况下,尝试按照您应该升级33个软件包的方式安装libpth2。我已经安装了“libpth2”,但仍然无法工作。我应该如何升级这33个软件包?我试过了,结果是:0个升级,0个新安装,0个删除,33个未升级。还可以试着这样做:sudo apt get install build essentialIn在这种情况下,尝试安装libpth2,您应该升级这33个软件包。我已经安装了“libpth2”,但仍然无法工作。我应该如何升级这33个软件包?它是大写的I,而不仅仅是-l标志!这是我的首都,而不仅仅是-l旗!