简体   繁体   中英

Makefile 'fdopen: Bad file descriptor' error

I'm making a makefile, and getting this error:

List.h:10:18: error: calling fdopen: Bad file descriptor

I have no idea why it happens. Here's the beginning of List.h:

#ifndef List_h__
#define List_h__

#include "Data.h"
#include "general.h"

where #include "Data.h" is the 10th line. Data and then general is the order in which the dependencies are written in the makefile:

List.o: List.cpp List.h Data.h general.h
    g++ List.cpp $(f)

data doesn't include anything and general includes only iostream, and no other class also includes iostream.

Here's Data.h:

#ifndef Data_h__
#define Data_h__

class Data
{
private:
public:
    //default constructor
    Data() {}
    //destructor
    virtual ~Data()=0;
    /*****************************************************************************
    * function name: operator<
    * The Input: This Data, other Data
    * The output: The operator will compare between two datas. The comparison will
    * be used to create a sorted list.
    *****************************************************************************/
    virtual bool operator<(const Data& other) const =0;
};

Data::~Data() {}

#endif //Data_h__

I initially had the trivial implementation of Data's destructor after the =0, and I've also tried to move the trivial implementations of the constructor and destructor to a .cpp file. All of the above didn't work. Please help - I've been stuck on this makefile for hours and it's driving me crazy! Thanks!

First, check to see if you are using precompiled headers. If so delete all the precompiled headers.

If that doesn't work, then I think this may help. There is a bug in some version of g++ with including a header multiple times in a single unit.

Look at see if you are including Data.h multiple times.


Precompiled headers: look for .gch files and delete them.

Precompiled header

Often large projects have many header files that are included in every source file. The time the compiler takes to process these header files over and over again can account for nearly all of the time required to build the project. To make builds faster, GCC allows users to `precompile' a header file; then, if builds can use the precompiled header file they will be much faster.

To create a precompiled header file, simply compile it as you would any other file, if necessary using the -x option to make the driver treat it as a C or C++ header file. You will probably want to use a tool like make to keep the precompiled header up-to-date when the headers it contains change.

A precompiled header file will be searched for when #include is seen in the compilation. As it searches for the included file (see Search Path) the compiler looks for a precompiled header in each directory just before it looks for the include file in that directory. The name searched for is the name specified in the #include with `.gch' appended. If the precompiled header file can't be used, it is ignored.

For instance, if you have #include "all.h", and you have all.h.gch in the same directory as all.h, then the precompiled header file will be used if possible, and the original header will be used otherwise.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM