对`pthread_create'的未定义引用 [英] undefined reference to `pthread_create'

查看:170
本文介绍了对`pthread_create'的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

all: LinServer LinClient

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

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

我也尝试了-lpthread,但存在相同的错误:

I also tried with -lpthread but same error:

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.

这篇关于对`pthread_create'的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆