Close() / write() was not declared in this scope

  • Find the code below. What i am doing wrong. The similar code works in plain GCC compliling. Brings the error close() was not declared in this scope. The same for write() . open() is Ok.

    @#ifndef KSEG_DH
    #define KSEG_DH

    #include "QtGlobal"
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/param.h>
    #include <sys/ioctl.h>
    #include <sys/types.h>
    #include </usr/include/sys/io.h>
    #include <sys/stat.h>
    #include <sys/errno.h>
    #include </usr/include/sys/fcntl.h>
    #include </usr/include/linux/mtio.h>
    #include "KSEG_D.h"
    int KSEG_D::CloseOutTape()
    close( idOutTape );
    return 0;

  • Do you mind to enlighten us and tell us the tool chain where the compile fails?

  • Exactly.

  • @#include </usr/include/sys/io.h>@

    is not a good idea:-) The compiler checks all the include pathes for the files you give and /usr/include is in the list of include pathes on any decent unix-based system. sys/types.h is already found and most likely located right next to sys/io.h.

    Are you planing on asking here about each and every method you need to include somewhere? You were the guy that asked about ioctl before, aren't you? Please check the documentation of the methods you use for the include files needed (or check /usr/include manually, or read a book, or check the working non-Qt code you have).

  • Thank you. You are so kind. I never asked if i am not sure that i tryed everything i can find out. Some people not so smart and need help

  • Ok, sorry if I was patronizing, but your question led me to believe that you did none of the following:

    check the documentation, e.g. by doing "man 2 close" to get the man page (assuming you are on a unix-oid OS, going by you including /usr/include)?

    check a book on C programming. close/open/write/read are pretty well described in any of them. C++ books on the other hand tend to not cover them to extensively since C++ provides more high level directives for file handling. Qt has some even more high level classes for that, too.

    google for "close function in linux"? That gets you the man page as the first hit.

    run "grep write /usr/include"? That will get you lots of hits, so that is most likely not the preferred way to go;-)

  • Thank you. I was out of the office, so can not reply promptly. The problem solved. Brief description:

    1. I could not find ioctl.h. It was really stupid error – I was testing the application on Widows platform that is not proper for ioctl
    2. The error aroused during compilation as close() ( read(), write() ) is not defined. In Linux to use this in *.cpp mtio.h needs to be included.

Log in to reply