[英]Having undefined reference to `pthread_join' error even using lpthread
I am using linux on ubuntu. 我在ubuntu上使用linux。 However, I am having problem even using pthread and lpthread.
但是,即使使用pthread和lpthread,我也遇到问题。 Please help!
请帮忙! Thank you in advance!
先感谢您!
yuki@ubuntu:~/NetBeansProjects/csci212A3$ g++ Path.o Maze.o SubmitMazeSoln.o TestSubmitMazeSoln.cpp -o -lpthread
In file included from Maze.h:12:0,
from TestSubmitMazeSoln.cpp:11:
Assignm3_Utils.h: In constructor ‘Point::Point()’:
Assignm3_Utils.h:17:19: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
Point () { x = NULL; y = NULL; }
^
Assignm3_Utils.h:17:29: warning: converting to non-pointer type ‘int’ from NULL [-Wconversion-null]
Point () { x = NULL; y = NULL; }
^
/tmp/ccMQbyoO.o: In function `newThread()':
TestSubmitMazeSoln.cpp:(.text+0x3ab2): undefined reference to `pthread_create'
TestSubmitMazeSoln.cpp:(.text+0x3b0a): undefined reference to `pthread_create'
TestSubmitMazeSoln.cpp:(.text+0x3b53): undefined reference to `pthread_join'
TestSubmitMazeSoln.cpp:(.text+0x3b79): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
Is this really an accurate copy of your command line: 这真的是您的命令行的准确副本吗?
g++ Path.o Maze.o SubmitMazeSoln.o TestSubmitMazeSoln.cpp -o -lpthread
The -o
option specifies the output file, and expects an argument. -o
选项指定输出文件,并需要一个参数。 As written above, this argument is -lpthread
. 如上所述,此参数是
-lpthread
。 So -lpthread
is not an argument (and the pthread library will not be searched); 因此
-lpthread
不是一个参数(并且不会搜索pthread库); it is the name of your output file. 它是您的输出文件的名称。 (And you don't really want an executable, or any file, with the name
-lpthread
; filenames which start with a -
cause no end of problems under Unix.) (而且,您实际上并不需要名称为
-lpthread
的可执行文件或任何文件;以-
开头的文件名在Unix下不会导致问题的解决。)
With regards to the warnings: I would guess from them that x
and y
in Point
have type int
. 关于警告:我会从他们那里猜测
Point
中的x
和y
类型为int
。 NULL
is the conventional way of specifying a null pointer, and using it as an int
is obfuscation in the first degree. NULL
是指定空指针的常规方式,并且在第一度中将其用作int
是混淆的。 So g++ warns. 因此,g ++警告。 (Of course, from C++11 on, one should prefer
nullptr
for a null pointer, rather than NULL
.) (当然,从C ++ 11开始,应该将
nullptr
用作null指针,而不是NULL
。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.