gpt4 book ai didi

c++ - 未定义对 `pthread_create' 的引用

转载 作者:行者123 更新时间:2023-12-03 03:27:30 26 4
gpt4 key购买 nike

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

all: LinServer LinClient

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

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

我也尝试过使用 -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

知道这里出了什么问题吗?

最佳答案

您应该使用-lpthread而不是-pthread

关于c++ - 未定义对 `pthread_create' 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17264984/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com