Error Calling Fdopen
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up calling fdopen: Bad file descriptor up vote 5 down vote favorite I'm getting the following error when trying to compile my program: calling fdopen: Bad file descriptor I've read this might be a problem related to including a precompiled header in one of my header files. The file which is causing the error includes the stdio.h header in it so I have access to the FILE type. If I remove this, the error disappears, but then I can't use the FILE type. Does anybody know how I can fix this? c gcc fdopen share|improve this question edited Sep 13 '11 at 4:08 Brian Webster 17.3k37115199 asked Feb 14 '10 at 19:43 LandonSchropp 3,8841247104 4 Try isolating the problem into a bare bones program (--i.e., a new seperate file with a main in it and only the code that fails). Then update your question. We can't give feedback without some code. –Hassan Syed Feb 14 '10 at 19:46 1 Can you post the simplest self-contained code that reproduces the issue you are experiencing? –Mark Byers Feb 14 '10 at 19:47 what version of gcc? –bmargulies Feb 14 '10 at 20:12 Source code please? We're not psychic debuggers nor clairvoyants... –t0mm13b Feb 16 '10 at 20:26 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote Hard to tell without details, but it's indeed most probably due to an out-of-date precompiled header. Remove all .gch files and try again. This is frequently reported as a bug against GCC, see the bugzilla entry here share|improve this answer answered Feb 16 '10 at 20:20 F'x 8,181553112 1 Thanks, this happened to be my issue. –Derrick May 21 '11 at 17:52 add a comment| up vote 0 down vote accepted Sorry, I just forgot to include the stdio.h header file. I feel kind of stupid now. share|improve this answer edited Sep 13 '11 at 4:09 Brian Webster 17.3k37115199 answered Feb 17 '10 at 3:49 LandonSchropp 3,8841247104 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign
last months will be deleted periodically to fight SPAM! Home Help Search Login Register Wiki Code::Blocks » Developer forums (C::B DEVELOPMENT STRICTLY!) » Development » fdopen: Bad file descriptor « previous next » Send this topic Print Pages: [1] Go Down Author Topic: fdopen: Bad file descriptor (Read 12697 times) killerbot Administrator Lives here! Posts: 4971 http://stackoverflow.com/questions/2262484/calling-fdopen-bad-file-descriptor fdopen: Bad file descriptor « on: August 14, 2007, 03:43:10 pm » Does anyone else get this on linux : Quoteif g++ -DHAVE_CONFIG_H -I. -I. -I../../src/include -I/usr/lib64/wx/include/gtk2-unicode-release-2.8 -I/usr/include/wx-2.8 -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -D__WXGTK__ -pthread -I../../src/include/wxscintilla/include -I../../src/include -I../../src/include/scripting/include -I../../src/include/scripting/sqplus -I../../src/include/wxFlatNotebook/include -I../../src/src/wxAUI -DENABLE_BINRELOC -DAPP_PREFIX="\"/usr/local\"" -Ulinux -Uunix -O2 -ffast-math -g -O2 -DCB_PRECOMP -Winvalid-pch http://forums.codeblocks.org/index.php?topic=6678.0 -fPIC -DPIC -fexceptions -MT app.o -MD -MP -MF ".deps/app.Tpo" -c -o app.o app.cpp; \ then mv -f ".deps/app.Tpo" ".deps/app.Po"; else rm -f ".deps/app.Tpo"; exit 1; fiIn file included from ../../src/include/logmanager.h:5, from app.cpp:55:../../src/include/logger.h:4:25: error: calling fdopen: Bad file descriptormake[3]: *** [app.o] Error 1 Logged killua Multiple posting newcomer Posts: 11 Re: fdopen: Bad file descriptor « Reply #1 on: August 14, 2007, 03:47:53 pm » Yeah, I got it just a bit ago, but I decided to do a make clean, and then a re-make. I'll see if I still get it after it gets to that point...[EDIT] Update: Still get the error after doing a make clean...will await a fix to be submitted before I proceed. « Last Edit: August 14, 2007, 03:58:51 pm by killua » Logged mandrav
that line, I simply have #include "AnotherFile.h" Google told me this has something to do with precompiled headers, http://www.cplusplus.com/forum/unices/1558/ but I can't figure out how to turn them off. 1) http://pubs.opengroup.org/onlinepubs/009695399/functions/fdopen.html how to turn off using precompiled headers with g++ flags? 2) what else would be causing this?? Thanks! Dave Apr 24, 2008 at 4:20am UTC rpgfan3233 (109) Try reordering the header files. I'm not sure if that will work, but it apparently worked error calling for some test code at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13675 The bug was an issue with precompiled headers being included twice, which may be the case here. The same issue with fdopen() came up in that instance. Perhaps your problem and that bug are related to each other. Apr 27, 2008 at 7:52pm UTC hcben00 (1) I don't check error calling fdopen here often so please forgive me if I never respond to any questions or responses... Solution to my similar problem after reading... Make sure the includes at the top of your headers and source are always in the same order and make sure the call to G++ is in the same order as listed in the top of the headers and source files. (Note: I didn't test the different combinations but I did get it to work my first try, this does assume the flexibility of having all sources.) Heres what I had trouble with 1
2
3
4
5
6
7
8
9
10
11
12
13
// Composition.h #include Increment.h #include Time.h // Composition.cpp #include "Composition.h" #include "Time.h" #include "Increment.h" // TestComposition.cpp #include "Time.h" #include "Increment.h" #include "Composition.h" my original G++ call g++ Increment.cpp Time.cpp Composition.cpp TestComposition.cpp -o TestComp My solution: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Composition.h (No difference) #include Increment.h #include Time.h // Composition.cpp (Big difference here) #include "Increment.h" #include "Time.h" #include "Composition.h" // TestComposition.cpp (Minor difference here) #include "Increment.h" #include "Time.h" #includ
file descriptor SYNOPSIS [CX] #include <stdio.h>
FILE *fdopen(int fildes, const char *mode); DESCRIPTION The fdopen() function shall associate a stream with a file descriptor. The mode argument is a character string having one of the following values: rorrb Open a file for reading. worwb Open a file for writing. aorab Open a file for writing at end-of-file. r+orrb+orr+b Open a file for update (reading and writing). w+orwb+orw+b Open a file for update (reading and writing). a+orab+ora+b Open a file for update (reading and writing) at end-of-file. The meaning of these flags is exactly as specified in fopen(), except that modes beginning with w shall not cause truncation of the file. Additional values for the mode argument may be supported by an implementation. The application shall ensure that the mode of the stream as expressed by the mode argument is allowed by the file access mode of the open file description to which fildes refers. The file position indicator associated with the new stream is set to the position indicated by the file offset associated with the file descriptor. The error and end-of-file indicators for the stream shall be cleared. The fdopen() function may cause the st_atime field of the underlying file to be marked for update. [SHM] If fildes refers to a shared memory object, the result of the fdopen() function is unspecified. [TYM] If fildes refers to a typed memory object, the result of the fdopen() function is unspecified. The fdopen() function shall preserve the offset maximum previously set for the open file description corresponding to fildes. RETURN VALUE Upon successful completion, fdopen() shall return a pointer to a stream; otherwise, a null pointer shall be returned and errno set to indicate the error. ERRORS The fdopen() function may fail if: [EBADF] The fildes argument is not a valid file descriptor. [EINVAL] The mode argument is not a valid mode. [EMFILE] {FOPEN_MAX} streams are currently open i