C语言 找不到 -lpthread?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21827392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:46:03  来源:igfitidea点击:

Cannot find -lpthread?

ceclipsepthreadsmingw

提问by matthewhang

I am new to C programming.

我是 C 编程的新手。

I was trying to use the pthread API to write some concurrent program.

我试图使用 pthread API 来编写一些并发程序。

I downloaded eclipse IDE for C/C++ Developers, MinGW. I have put all the library, header files into the corresponding location of the MinGW file.

我为 C/C++ 开发人员下载了 Eclipse IDE,MinGW。我已经把所有的库、头文件放到了MinGW文件的对应位置。

When I tried to build the project, there is always an error "cannot find -lpthread", what happened? I have added the "-pthread" to the GCC compiler.

当我尝试构建项目时,总是出现“找不到-lpthread”的错误,这是怎么回事?我已将“-pthread”添加到 GCC 编译器。

I have searched a lot in Google but seems no one have similar problem as me.

我在 Google 上搜索了很多,但似乎没有人遇到与我类似的问题。

回答by APaul

The answer to this questionby someone who is also missing MinGW pthread library should help you out! Essentially the issue is that the MinGW installer script might not download the lpthread library upon installation. Quoted from link:

同样缺少 MinGW pthread 库的人对这个问题的回答应该可以帮助您!本质上,问题在于 MinGW 安装程序脚本可能不会在安装时下载 lpthread 库。引自链接:

Just run and open MinGW Installation Manager, which should be pre-installed with MinGW, select "All Packages" on the left panel, and on the right panel, search for "mingw32-pthreads-w32" packages and install them.

只需运行并打开 MinGW 安装管理器,它应该预先安装有 MinGW,在左侧面板上选择“所有包”,在右侧面板上,搜索“mingw32-pthreads-w32”包并安装它们。

回答by alk

I downloaded eclipse IDE for C/C++ Developers, MinGW.

我为 C/C++ 开发人员下载了 Eclipse IDE,MinGW。

MingGW uses the Windows API. The Windows API does not provide PThreads.

MingGW 使用 Windows API。Windows API 不提供 PThreads。

You need to install PThreads for Win32to have PThreads available under Windows, and with this available under MinGW.

您需要为 Win32安装PThreads才能在 Windows 下使用 PThreads,并且在 MinGW 下可用。

回答by vinod

Eclipse is not configured to put the -pthread argument in the gcc compilation. To solve this, go to the Menu: view sourceprint? 1.Project -> Properties

Eclipse 未配置为将 -pthread 参数放入 gcc 编译中。要解决此问题,请转到菜单:查看源打印?1.项目->属性

From the bar on the left: view sourceprint? 1.c/c++ build -> GCC C Compiler -> Miscellaneous

从左侧的栏中:查看 sourceprint?1.c/c++ build -> GCC C Compiler -> Miscellaneous

Add the “-pthread” argument into the beginning of the “Other Flags” Also go to: view sourceprint? 1.c/c++ build -> Settings -> GCC C Linker -> Libraries

将“-pthread”参数添加到“Other Flags”的开头另请参阅:查看源打印?1.c/c++ build -> Settings -> GCC C Linker -> Libraries

And include the “pthread”library into the other libraries. Click Apply and rebuild the project. Pthreads must work now.

并将“pthread”库包含到其他库中。单击应用并重建项目。Pthreads 现在必须工作。

回答by minghua

See the question on mingw.org. I ended up with adding 'C:/cygwin/lib'to the settings for the "Library search path (-L)" at properties >> c/c++ build >> settings >> MinGW C Linker >> Libraries.

请参阅mingw.org 上问题。我最终'C:/cygwin/lib'properties >> c/c++ build >> settings >> MinGW C Linker >> Libraries.