Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/132.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 未定义对'pthread_create';_C++_Makefile_Pthreads - Fatal编程技术网

C++ 未定义对'pthread_create';

C++ 未定义对'pthread_create';,c++,makefile,pthreads,C++,Makefile,Pthreads,我有客户机-服务器代码。LinServer.cpp使用pthread连续侦听客户端。我创建了make文件来编译所有组件: all: LinServer LinClient LinServer: g++ LinServer.cpp -o LinServer -pthread LinClient: g++ LinClient.cpp -o LinClient -pthread 我还尝试了使用-lpthread,但出现了相同的错误: LinServer.cpp:(

我有客户机-服务器代码。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

为了执行make文件,我使用“make”命令-1来表示不使用“-Wall”:)你能详细说明一下@kfsonethecure在假定的副本中是无效的吗?现在怎么办?@user2500861:你的编译器命令行不应该有
-lpthread
(注意字母“L”)除了
-pthread
?还要确保顺序正确:它必须在命令行中的对象文件之后进入命令行在makefile中我犯了错误,我需要包括我丢失的-lpthread@我试过了,你是对的,但我很好奇为什么?谢谢