问题:

将一个c文件改为cpp文件,其中的perror()改用C++中的std::cerr << strerror(error) << std::endl;来替换。

重新编译文件,出现错误:

david@ubuntu:~/wrk/tmp/cpp_src/sysapps$ make
g++ -g3 -Wall -o0 -c message_recv.cpp -o message_recv.o
message_recv.cpp: In constructor ‘Message_recv::Message_recv()’:
message_recv.cpp:59:45: error: ‘errno’ was not declared in this scope
message_recv.cpp:66:47: error: ‘errno’ was not declared in this scope
message_recv.cpp: In destructor ‘virtual Message_recv::~Message_recv()’:
message_recv.cpp:76:47: error: ‘errno’ was not declared in this scope
message_recv.cpp: In member function ‘virtual void* Message_recv::run()’:
message_recv.cpp:87:51: error: ‘errno’ was not declared in this scope
make: *** [message_recv.o] Error 1
david@ubuntu:~/wrk/tmp/cpp_src/sysapps$

解决办法:

1. 原来的perror()需要用到头文件<stdio.h>,而strerror()只需要用到头文件<string.h>,

所以,重新编译时,将<stdio.h>替换为<string.h>。

2. errno无疑是一个系统定义的全局变量,不是由用户来声明或定义的。

查到<errno.h>中有这样的宏定义

#ifndef errno
extern int errno;
#endif

将头文件<errno.h>包含到程序中,重新编译,编译顺利完成。

问题解决。

最新文章

  1. 解决Android界面布局添加EditText组件后界面无法预览
  2. c# Wndproc的使用方法
  3. 用Get-ADComputer取非常用属性的值
  4. 第二个Sprint冲刺第九天
  5. Cookielib
  6. IO输入输出 2
  7. spring aop配置文档部分翻译
  8. performance_schema 变量
  9. 用Python实现gmail邮箱服务,实现两个邮箱之间的绑定(上)
  10. LayoutInflater (转)
  11. 用js来实现那些数据结构12(散列表)
  12. Nodejs实现用户注册
  13. 4. VIM 系列 - 认识VIM的缓冲区、窗口、标签页
  14. JGUI源码:实现日期控件显示(17)
  15. Python与R的区别和联系
  16. React-异步组件及withRouter路由方法的使用
  17. maven自动打包上传nexus仓库配置
  18. Spring MVC和Spring Data JPA之按条件查询和分页(kkpaper分页组件)
  19. CTF-练习平台-Misc之 又是一张图片,还单纯吗??
  20. BugPhobia贡献篇章:团队贡献分值与转会确定

热门文章

  1. vue实践---vue结合 promise 封装原生ajax
  2. web安全之SQL注入---第四章 如何进行SQL注入攻击
  3. CF:Problem 426B - Sereja and Mirroring 二分或者分治
  4. TP框架的修改,删除
  5. 信息搜集之google语法
  6. visual studio2017 无法添加引用 未能加载包ReferenceManagerPackage not such interface support 解决方法
  7. effect request
  8. 【转载】解决Apache2+PHP上传文件大小限制的问题
  9. zip 解压脚本
  10. Android Studio实现代码混淆