即使使用 lpthread 也未定义对"pthread_join"错误的引用
Having undefined reference to `pthread_join' error even using lpthread
我在ubuntu上使用linux。然而,我甚至在使用pthread和lpthread时也遇到了问题。请帮忙!提前谢谢!
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
这真的是命令行的准确副本吗:
g++ Path.o Maze.o SubmitMazeSoln.o TestSubmitMazeSoln.cpp -o -lpthread
-o
选项指定输出文件,并需要一个参数。如上所述,这个自变量是-lpthread
。因此-lpthread
是而不是参数(并且不会搜索pthread库);它是输出文件的名称。(你并不真的想要一个名为-lpthread
的可执行文件或任何文件;在Unix下,以-
开头的文件名会带来很多问题。)
关于警告:我猜Point
中的x
和y
的类型为int
。NULL
是指定空指针的传统方式,将其用作int
在第一程度上是混淆。因此g++发出警告。(当然,从C++11开始,应该更喜欢nullptr
作为空指针,而不是NULL
。)
相关文章:
- 将对象数组的引用传递给函数
- 什么时候在C++中返回常量引用是个好主意
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 何时在引用或唯一指针上使用移动语义
- 如何在c++中使用引用实现类似python的行为
- 编译C++时未定义的引用
- Ctypes wstring通过引用传递
- c++r值引用应用于函数指针
- 理解c++中的引用
- C++取消引用指针.为什么会发生变化
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 强制转换为引用类型
- 引用一个已擦除类型(void*)的指针
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 具有默认值的引用获取函数
- 如何使用基类指针引用派生类成员
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- 如何引用基类的派生类?