问题:

将一个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的更多相关文章

  1. error: 'LOGE' was not declared in this scope

    移植了下HAL,发现编译出现如下错误 error: 'LOGE' was not declared in this scope 比较了一下android4.1的 system/core/include ...

  2. 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 ...

  3. 【QT】error: 'SIGNAL' was not declared in this scope

    error: 'SIGNAL' was not declared in this scope  未在此范围内声明. connect(ui->Btnshowhello,SIGNAL(clicked ...

  4. [Error] 'exit' was not declared in this scope的解决方法

    新手刚开始用Linux和c++写程序,可能会出现下面的错误 error: ‘exit’ was not declared in this scope 解决方法是 添加 #include <cst ...

  5. 解决Cygwin编译cocos2dx 遇到的 error: 'UINT64_C' was not declared in this scope 问题

    环境工具:Win10.VS2013.cocos2d-x-2.2.6.Cygwin.ADT 问题来源:写了一个小游戏,VS2013上运行成功,就尝试着打包apk,项目导入到ADT里面,添加了cocos2 ...

  6. 编译是报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 ...

  7. 调用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 解决: ...

  8. 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 ...

  9. error: ‘to_string’ was not declared in this scope

    错误: error: ‘to_string’ was not declared in this scope 原因: to_string是C++11引入的新功能,旧版本编译器可能不支持它,所以要给编译器 ...

随机推荐

  1. python第三方库地址

    python第三方库的地址: requests: http://docs.python-requests.org/zh_CN/latest/user/quickstart.html beautifus ...

  2. Laravel开发:Laravel核心——Ioc服务容器

    服务容器 在说 Ioc 容器之前,我们需要了解什么是 Ioc 容器. Laravel 服务容器是一个用于管理类依赖和执行依赖注入的强大工具. 在理解这句话之前,我们需要先了解一下服务容器的来龙去脉:  ...

  3. iOS系统层次架构

    本文转自:http://blog.csdn.net/lxl_815520/article/details/51172917 一,概述 iOS的系统架构分为四个层次:核心操作系统层(Core OS la ...

  4. js网页视频播放: vcastr22 、 flowplayer 、 jwplayer

    实例结构: 实例1: demo.html <embed src="vcastr22.swf?vcastr_file=../wujiandao.flv" allowFullSc ...

  5. 我的Android进阶之旅------>android:drawableLeft的用法

    有时候想在EditText左边放一个图片,如图所示: 就可以在xml布局文件中的EditText定义代码中,添加入下面的代码,即可实现: android:drawableLeft="@dra ...

  6. Django与Vue语法冲突问题完美解决方法

    当我们在django web框架中,使用vue的时候,会遇到语法冲突. 因为vue使用{{}},而django也使用{{}},因此会冲突. 解决办法1: 在django1.5以后,加入了标签: {% ...

  7. C# ADO.NET学习

    Connetction 对象: 数据库服务器 数据库名字 登录名.密码 连接数据库所需要的其他参数 Command对象: ExecuteScalar();//首行首列的内容 ExecuteNomQue ...

  8. 10 个经典PHP函数

    这篇文章主要介绍了php中的10个比较经典的函数,不太常见,可以满足有特殊需求的朋友 1. sys_getloadavg() sys_getloadavt()可以获得系 统负载情况.该函数返回一个包含 ...

  9. Redis持久化——RDB(一)

    核心知识点: 1.RDB:将当前数据生成快照保存到硬盘 2.手动触发 save:会阻塞Redis服务器直到RDB完成. bgsave:执行fork创建子进程,由子进程负责RDB操作,阻塞只发生在for ...

  10. QCon2016 上海会议汇总(2) - 团队管理

    QCon 2016上海日程:http://2016.qconshanghai.com/schedule <当你的团队还支撑不起梦想时> - 链尚网技术合伙人 杨荣伟 Figo讲述了如何训练 ...