如何在CLion的C项目中使用pthread头文件,在windows中使用MinGW。

问题描述 投票:0回答:1

我正试图加入 #include <pthread.h> 在我使用CLion的项目中,我不能直接使用它。有什么特别的方法可以将pthread包含到C项目中吗?

c pthreads
1个回答
3
投票

我终于想到了一个解决办法。由于我使用的是MinGW,我使用了MinGW安装管理器,并安装了需要在CLion中执行pthreads和openmp相关任务的包。下面是安装过程。

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

enter image description here

然后进入installtion -> Apply changes来安装新的包。你可以在你的c或c++程序中使用pthread.h和omp.h,没有任何问题。


2
投票

添加 -lpthread 标志,即在编译过程中使用了

 gcc foo.c -lpthread

更多信息在这里 为什么你需要'-lpthread'?

© www.soinside.com 2019 - 2024. All rights reserved.