C++ 对“pthread_create”的未定义引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17264984/
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-08-27 21:03:35  来源:igfitidea点击:

undefined reference to `pthread_create'

c++makefilepthreads

提问by Mats Petersson

I have client server code. LinServer.cpp using pthread to continuously listen client. I created make file to compile all togather:

我有客户端服务器代码。LinServer.cpp 使用 pthread 持续监听客户端。我创建了 make 文件来编译所有内容:

all: LinServer LinClient

    LinServer:
    g++ LinServer.cpp -o LinServer -pthread

    LinClient:
    g++ LinClient.cpp -o LinClient -pthread

I also tried with -lpthread but same error:

我也试过 -lpthread 但同样的错误:

LinServer.cpp:(.text+0x29b): undefined reference to `pthread_create'
LinServer.cpp:(.text+0x2a7): undefined reference to `pthread_detach'
collect2: error: ld returned 1 exit status
make: *** [LinServer] Error 1

Any idea what's the problem here?

知道这里有什么问题吗?

回答by Mats Petersson

You should use -lpthreadnot -pthread.

你应该使用-lpthreadnot -pthread