此文档主要记录学习过程中出现的一些问题.
环境配置
学习unix高级环境编程这本书时,发现#include”apue.h”报错,在网上查找后发现这是作者自己写的一个包,需要自己手动添加到/usr/include目录下,所以从网上找了一个教程配置了下,成功配好了环境.具体过程不赘述了,直接参考的参考文献中的第二条链接.运行程序过程中出现的错误
报错信息:1
2
3
4
5gcc main.cpp -o th2 -lpthread
/tmp/ccdz0db3.o:在函数‘__static_initialization_and_destruction_0(int, int)’中:
main.cpp:(.text+0x186):对‘std::ios_base::Init::Init()’未定义的引用
main.cpp:(.text+0x19b):对‘std::ios_base::Init::~Init()’未定义的引用
collect2: error: ld returned 1 exit status报错原因:使用了c编译器来编译c++文件
解法办法:使用命令[g++ main.cpp -o th2 -lpthread]来编译
https://blog.csdn.net/u010758410/article/details/78704003报错信息
1
2
3
4g++ thread_exit_test.cpp -o exit -lpthread
thread_exit_test.cpp: In function ‘int main()’:
thread_exit_test.cpp:47:43: error: lvalue required as unary ‘&’ operand
err = pthread_join(tid1, &((void *) fp));报错原因:C语言编译器允许隐含性的将一个通用指针转换为任意类型的指针,而C++不允许的。
解法方法:https://blog.csdn.net/alpelious/article/details/53486547
参考文献
[1] http://www.apuebook.com/
[2] https://www.jianshu.com/p/c51a4127e9e6