【问题标题】:How to use pthread header file in C project in CLion which uses MinGW in windows如何在 Windows 中使用 MinGW 的 CLion 中的 C 项目中使用 pthread 头文件
【发布时间】:2020-04-27 10:48:20
【问题描述】:

我正在尝试在使用 CLion 的项目中包含 #include <pthread.h>,但我无法直接使用它。是否有任何特定方法可以将 pthread 包含到 C 项目中?

【问题讨论】:

    标签: c pthreads


    【解决方案1】:

    我终于想出了一个解决方案。由于我使用的是 MinGW,因此我使用了 MinGW 安装管理器并安装了需要在 CLion 中执行 pthread 和 openmp 相关任务的包。这是程序。

    打开安装管理器后转到所有包,选择使用mingw32-pthreads-w32命名的选择包并选择它们进行安装。

    然后转到安装 -> 应用更改以安装新软件包。您可以在您的 c 或 c++ 程序中使用 pthread.h 和 omp.h 没有任何问题。

    【讨论】:

      【解决方案2】:

      在编译中添加 -lpthread 标志,即:

       gcc foo.c -lpthread
      

      更多信息在这里:Why do you need '-lpthread'?

      【讨论】:

      • 实际上pthread文件不能被包含,因为它给出了一个文件找不到错误。
      • 尝试在终端中运行:find / -name 'libpthread.so' -print
      猜你喜欢
      • 2020-11-02
      • 1970-01-01
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-28
      • 2017-07-09
      • 1970-01-01
      相关资源
      最近更新 更多