问题:

将一个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. byte[] 、Bitmap与Drawbale 三者直接的转换

    经常遇到这种类似头疼的问题 byte[] .Bitmap与Drawbale 三者直接的转换 1.byte[] ->Bitmap Bitmap Bitmap = BitmapFactory.dec ...

  2. CAFFE学习笔记(四)将自己的jpg数据转成lmdb格式

    1 引言 1-1 以example_mnist为例,如何加载属于自己的测试集? 首先抛出一个问题:在example_mnist这个例子中,测试集是人家给好了的.那么如果我们想自己试着手写几个数字然后验 ...

  3. (转)深入理解Java内存模型之系列篇

    原文地址: http://blog.csdn.net/ccit0519/article/details/11241403 深入理解Java内存模型(一)——基础 并发编程模型的分类 在并发编程中,我们 ...

  4. python字符串基本方法

    字符串类型在Python中是十分重要的类型,他一般用引号中间添加字符的形式表达,不同于其他语言的是,Python中双引号(” “)与单引号(’ ‘)是不予区分的.都可以用来表示字符串 创建.赋值和访问 ...

  5. x-www-form-urlencoded名字的由来

    1 提交的是表单数据 所以用form. 2 提交的形式是以参数放在url后面的形式提交的 例如,以x1=y1&x2=y2&x3=y3的形式放在url后面的形式提交,所以是urlenco ...

  6. git clone了整个远程仓库分支

    git之远程标签下载(远程分支) 一般我们发布一个新版本到线上服务器时都会在版本库中打一个标签,这样我们可以随时查看这个打标签的版本,就是说标签其实是版本库中一个快照.git的标签与分支类似,区别是分 ...

  7. mysql 分页测试,

    大环境:MySQL5.6 自己造了 27万数据, 一次性 查出来,会超时: 而分页跑,会查出来8s: 但是在少于27万时,直接查比 分页查快5倍:

  8. Storm,Spark和Samza

    http://www.csdn.net/article/2015-03-09/2824135 Apache Storm 在Storm中,先要设计一个用于实时计算的图状结构,我们称之为拓扑(topolo ...

  9. 重新认识Java中的程序入口即主函数各组成部分

    主函数各组成部分深入理解 public static void main(String[] agrs) 主函数:是一个特殊的函数,作为程序的入口,可以被JVM调用 主函数的定义: public:代表着 ...

  10. 【leetcode刷题笔记】Divide Two Integers

    Divide two integers without using multiplication, division and mod operator. 题解:要求不用乘除和取模运算实现两个数的除法. ...