error: ‘errno’ was not declared in this scope
问题:
将一个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>包含到程序中,重新编译,编译顺利完成。
问题解决。
error: ‘errno’ was not declared in this scope的更多相关文章
- error: 'LOGE' was not declared in this scope
移植了下HAL,发现编译出现如下错误 error: 'LOGE' was not declared in this scope 比较了一下android4.1的 system/core/include ...
- c++ - fcgio.cpp:50: error: 'EOF' was not declared in this scope - Stack Overflow
c++ - fcgio.cpp:50: error: 'EOF' was not declared in this scope - Stack Overflow fcgio.cpp:50: error ...
- 【QT】error: 'SIGNAL' was not declared in this scope
error: 'SIGNAL' was not declared in this scope 未在此范围内声明. connect(ui->Btnshowhello,SIGNAL(clicked ...
- [Error] 'exit' was not declared in this scope的解决方法
新手刚开始用Linux和c++写程序,可能会出现下面的错误 error: ‘exit’ was not declared in this scope 解决方法是 添加 #include <cst ...
- 解决Cygwin编译cocos2dx 遇到的 error: 'UINT64_C' was not declared in this scope 问题
环境工具:Win10.VS2013.cocos2d-x-2.2.6.Cygwin.ADT 问题来源:写了一个小游戏,VS2013上运行成功,就尝试着打包apk,项目导入到ADT里面,添加了cocos2 ...
- 编译是报error: 'EVNET_COME_TO_FOREGROUND' was not declared in this scope
Compile++ thumb : game_shared <= main.cpp jni/hellocpp/main.cpp: In function 'void Java_org_coco ...
- 调用ffmpeg库编译时出现common.h:175:47: error: 'UINT64_C' was not declared in this scope
解决办法 出现错误:jni/ffmpeg/libavutil/common.h:175:47: error: 'UINT64_C' was not declared in this scope 解决: ...
- In function 'int av_clipl_int32_c(int64_t)': error: 'UINT64_C' was not declared in this scope
cygwin下使用ndk编译jni时遇到的错误: /ffmpeg/include/libavutil/common.h: In function 'int av_clipl_int32_c(int64 ...
- error: ‘to_string’ was not declared in this scope
错误: error: ‘to_string’ was not declared in this scope 原因: to_string是C++11引入的新功能,旧版本编译器可能不支持它,所以要给编译器 ...
随机推荐
- 探究css中各种情况下的元素的垂直和水平居中的问题(面试题)
今天各种纠结,真的是不想写东西(ps 我比较懒)但是老是有人问这个问题,于是我就本着分享精神还是整理一下,好了废话不多说 开始上代码 问题:外边是一个容器,容器中还有一个容器,那么请问怎么让里边的容器 ...
- web 网页截取图片
关于在UIwebview上添加滚动图片 两种滚动手势会混淆,应为webview有webview.scrollview的属性 故参照昨天的随笔 scrollview嵌套解决方案. 本篇随笔主要讲循环使用 ...
- python函数式编程-------python2.7教程学习【廖雪峰版】(五)
2017年6月13日19:08:13 任务: 看完函数式编程 笔记: 该看:函数式编程1.函数是Python内建支持的一种封装,我们通过把大段代码拆成函数,通过一层一层的函数调用,就可以把复杂任务分解 ...
- Python中使用__new__实现单例模式并解析
阅读文章前请先阅读 Python中类方法.__new__方法和__init__方法解析 单例模式是一个经典设计模式,简要的说,一个类的单例模式就是它只能被实例化一次,实例变量在第一次实例化时就已经固定 ...
- sudo npm install -g cnpm --registry=https://registry.npm.taobao.org
- 【BZOJ3316】JC loves Mkk 分数规划+单调队列
[BZOJ3316]JC loves Mkk Description Input 第1行,包含三个整数.n,L,R.第2行n个数,代表a[1..n]. Output 仅1行,表示询问答案.如果答案是整 ...
- CAFFE学习笔记(三)在VS2013下生成需要的exe文件
如我们所知,CAFFE_ROOT下有一个文件夹叫tools,里面中有许多cpp文件,它们各自有其不同的功能.但是很显然,当我们要完成某样工作时,我们是不能直接用cpp文件的,只能用exe文件.如何利用 ...
- EasyDSS+EasyNVR实现幼儿园直播/工地直播等分权限观看直播视频的功能
在EasyNVR互联网直播服务器使用说明书中有关于EasyNVR分组的介绍: "EasyNVR的功能定位就是为视频应用层输出视频设备接入/标准视频输出的能力平台层,只做基础的视频通道接入.视 ...
- Qt状态机框架(状态机就开始异步的运行了,也就是说,它成为了我们应用程序事件循环的一部分了)
状态机框架 Qt中的状态机框架为我们提供了很多的API和类,使我们能更容易的在自己的应用程序中集成状态动画.这个框架是和Qt的元对象系统机密结合在一起的.比如,各个状态之间的转换是通过信号触发的,状态 ...
- Adam 算法
简介 Adam 是一种可以替代传统随机梯度下降(SGD)过程的一阶优化算法,它能基于训练数据迭代地更新神经网络权重.Adam 最开始是由 OpenAI 的 Diederik Kingma 和多伦多大学 ...