zoukankan      html  css  js  c++  java
  • 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>包含到程序中,重新编译,编译顺利完成。


    问题解决。



  • 相关阅读:
    Xamarin.Forms之界面设计原则
    Xamarin.Forms之异步
    Xamarin Studio常见问题
    Xamarin.Forms之Button
    Xamarin.Forms之MessagingCenter
    Xamarin.Forms之Frame布局
    Xamarin.Forms之OnPlatform的使用
    2018/11/7 20:47:57
    2018/11/6
    2018/11/5 每日分析-test
  • 原文地址:https://www.cnblogs.com/java20130726/p/3218472.html
Copyright © 2011-2022 走看看