为什么在 IDE 中"undefined reference to `_imp__pthread_create"错误?

why the error "undefined reference to `_imp__pthread_create" in IDE?

本文关键字:pthread imp create 错误 to IDE undefined reference 为什么      更新时间:2023-10-16

我在windows IDE的Dev c++中得到了两个错误的undefined reference to _imp__pthread_createundefined reference to _imp__pthread_join,我使用的是Dev c++ 5.4.1。为什么会出现这个错误?我该如何解决这个问题?有人能告诉我吗?非常感谢您的时间!!

    #include<iostream>
    #include<pthread.h>
    using namespace std;
    
    void *uss_thread(void*){
        
        cout<<"hello";
    }
    
    main()
    {
         pthread_t tid1;    
         pthread_create(&tid1, NULL, &uss_thread, NULL);
         pthread_join(tid1,NULL);
    }

因为你没有链接到lib pthread

下载DevPack

  • 安装在Dev c++
  • 在Dev c++中创建新项目
  • 然后转到项目菜单->项目选项->在那个选择"参数选项卡"
  • 选择"添加库或对象"选项
  • libpthreadGC2 SelectIt"。Dev ++安装目录下的文件:它将在LIB目录下。
  • 按Ok

祝你好运