How to use pthread header file in C project in CLion which uses MinGW in windows

时光总嘲笑我的痴心妄想 提交于 2020-05-09 05:29:05

问题


I am trying to include #include <pthread.h> in my project which uses CLion but I am cannot use it directly. Is there any specific way to include pthread to a C project?


回答1:


I finally came up with a solution. Since I am using MinGW I Used MinGW installation manager and install packages that need to execute pthreads and openmp related tasks in CLion. Here is the procedure.

After opening the installation manager go to all packages and select the select packages named using mingw32-pthreads-w32 and select them for installation.

Then go to the installtion -> Apply changes to install new packages. The you can use pthread.h and omp.h inside your c or c++ program without any problem.




回答2:


Add -lpthread flag to the compilation, i.e:

 gcc foo.c -lpthread

more info here: Why do you need '-lpthread'?



来源:https://stackoverflow.com/questions/61457121/how-to-use-pthread-header-file-in-c-project-in-clion-which-uses-mingw-in-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!