When trying to compile some headers g++ says: calling fdopen: Bad file descriptor See fix for more information. Environment: System: Linux hell.hell.gr 2.6.5 #31 Sun Apr 11 18:07:49 EEST 2004 i686 unknown unknown GNU/Linux Architecture: i686 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: ../gcc-3.4.0/configure --enable-threads=posix --prefix=/usr --enable-languages=c,c++ --enable-shared --with-arch=pentium3 --with-cpu=pentium3 --enable-__cxa_atexit How-To-Repeat: Use this Makefile in qt-3.2.1 include directory: --- CC=g++ -c -pipe -I/usr/local/postgre/include -I/usr/local/include -I/usr/local/X11/include -I/usr/local/progs/CUPS/include -I/usr/X11R6/include -I/usr/local/ssl/include -fno-exceptions -w -O3 -fprofile-generate -mmmx -ffast-math -fmessage-length=0 -fomit-frame-pointer -D_REENTRANT -fPIC -DQT_SHARED -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_THREAD_SUPPORT -DQT_NO_NIS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DQT_NO_XINERAMA -DQT_BUILTIN_GIF_READER=1 -DQT_NO_STYLE_MAC -DQT_NO_STYLE_AQUA -DQT_NO_STYLE_INTERLACE -DQT_NO_STYLE_WINDOWSXP -DQT_NO_STYLE_COMPACT -I/mnt/extra/usr/local/qt-x11-free-3.2.3/mkspecs/linux-g++ -I. -I../../include/freetype2 -I3rdparty/opentype -I../include -I/usr/X11R6/include -I/usr/X11R6/include -I../src/.moc/release-shared-mt/ gch: for fn in *.h ; do \ if ! test -f $$fn.gch || test $$fn -nt $$fn.gch ; then \ echo "${CC} $$fn -o $$fn.gch || true "; \ ${CC} $$fn -o $$fn.gch || true ; \ fi ; \ done %.h.gch: %.h ${CC} $< -o $@ all: gch --- This will work on most headers but will give fdopen errors on some of them.
Fix: Let's have an example: g++ -c -pipe -I/usr/local/postgre/include -I/usr/local/include -I/usr/local/X11/include -I/usr/local/progs/CUPS/include -I/usr/X11R6/include -I/usr/local/ssl/include -fno-exceptions -w -O3 -fprofile-generate -mmmx -ffast-math -fmessage-length=0 -fomit-frame-pointer -D_REENTRANT -fPIC -DQT_SHARED -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_THREAD_SUPPORT -DQT_NO_NIS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DQT_NO_XINERAMA -DQT_BUILTIN_GIF_READER=1 -DQT_NO_STYLE_MAC -DQT_NO_STYLE_AQUA -DQT_NO_STYLE_INTERLACE -DQT_NO_STYLE_WINDOWSXP -DQT_NO_STYLE_COMPACT -I/mnt/extra/usr/local/qt-x11-free-3.2.3/mkspecs/linux-g++ -I. -I../../include/freetype2 -I3rdparty/opentype -I../include -I/usr/X11R6/include -I/usr/X11R6/include -I../src/.moc/release-shared-mt/ qftp.h -o qftp.h.gch In file included from qdatastream.h:42, from qmap.h:44, from qmime.h:43, from qevent.h:45, from qobject.h:45, from qnetworkprotocol.h:45, from qftp.h:44: qiodevice.h:43:22: calling fdopen: Bad file descriptor Next we look at line 43 of qiodevice.h: #include "qcstring.h" Now we remove qcstring.h.gch and it works (!). There are cases where you've to remove more than one .gch files. Next we recreate qcstring.h.gch: g++ -c -pipe -I/usr/local/postgre/include -I/usr/local/include -I/usr/local/X11/include -I/usr/local/progs/CUPS/include -I/usr/X11R6/include -I/usr/local/ssl/include -fno-exceptions -w -O3 -fprofile-generate -mmmx -ffast-math -fmessage-length=0 -fomit-frame-pointer -D_REENTRANT -fPIC -DQT_SHARED -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_THREAD_SUPPORT -DQT_NO_NIS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DQT_NO_XINERAMA -DQT_BUILTIN_GIF_READER=1 -DQT_NO_STYLE_MAC -DQT_NO_STYLE_AQUA -DQT_NO_STYLE_INTERLACE -DQT_NO_STYLE_WINDOWSXP -DQT_NO_STYLE_COMPACT -I/mnt/extra/usr/local/qt-x11-free-3.2.3/mkspecs/linux-g++ -I. -I../../include/freetype2 -I3rdparty/opentype -I../include -I/usr/X11R6/include -I/usr/X11R6/include -I../src/.moc/release-shared-mt/ qcstring.h -o qcstring.h.gch And retry the qftp.h: # g++ -c -pipe -I/usr/local/postgre/include -I/usr/local/include -I/usr/local/X11/include -I/usr/local/progs/CUPS/include -I/usr/X11R6/include -I/usr/local/ssl/include -fno-exceptions -w -O3 -fprofile-generate -mmmx -ffast-math -fmessage-length=0 -fomit-frame-pointer -D_REENTRANT -fPIC -DQT_SHARED -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_THREAD_SUPPORT -DQT_NO_NIS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DQT_NO_XINERAMA -DQT_BUILTIN_GIF_READER=1 -DQT_NO_STYLE_MAC -DQT_NO_STYLE_AQUA -DQT_NO_STYLE_INTERLACE -DQT_NO_STYLE_WINDOWSXP -DQT_NO_STYLE_COMPACT -I/mnt/extra/usr/local/qt-x11-free-3.2.3/mkspecs/linux-g++ -I. -I../../include/freetype2 -I3rdparty/opentype -I../include -I/usr/X11R6/include -I/usr/X11R6/include -I../src/.moc/release-shared-mt/ qftp.h -o qftp.h.gch In file included from qdatastream.h:42, from qmap.h:44, from qmime.h:43, from qevent.h:45, from qobject.h:45, from qnetworkprotocol.h:45, from qftp.h:44: qiodevice.h:43:22: calling fdopen: Bad file descriptor (same thing) I ran the g++ command under 'strace -f' and I found this: [pid 13530] stat64("qstring.h.gch", {st_mode=S_IFREG|0640, st_size=6524666, ...}) = 0 [pid 13530] open("qstring.h.gch", O_RDONLY|O_NOCTTY) = 5 [pid 13530] fstat64(5, {st_mode=S_IFREG|0640, st_size=6524666, ...}) = 0 [pid 13530] read(5, "gpch+012", 8) = 8 [pid 13530] read(5, "\21\21\5\0\1\0\0\0\240\24\t\10$\0\0\0", 16) = 16 ... a lot of read()s ... ... some other stuff (but no close()) ... [pid 13530] read(5, "\23\0\0\0\21\0\0\0_G_HAVE_PRINTF_FP 1\24\0\0\0\22"..., 4096) = 3834 [pid 13530] brk(0) = 0x8580000 [pid 13530] brk(0x8582000) = 0x8582000 [pid 13530] close(5) = 0 [pid 13530] munmap(0x402d9000, 4096) = 0 [pid 13530] close(5) = -1 EBADF (Bad file descriptor) [pid 13530] open("qvariant.h", O_RDONLY|O_NOCTTY) = 5 [pid 13530] fstat64(5, {st_mode=S_IFREG|0664, st_size=10157, ...}) = 0 [pid 13530] brk(0) = 0x8582000 [pid 13530] brk(0x8585000) = 0x8585000 [pid 13530] read(5, "/*******************************"..., 10157) = 10157 [pid 13530] close(5) = 0 [pid 13530] fcntl64(-1, F_GETFL) = -1 EBADF (Bad file descriptor) [pid 13530] write(2, "In file included from qdatatable"..., 37In file included from qdatatable.h:42) = 37 [pid 13530] write(2, ":\n", 2: ) = 2 [pid 13530] write(2, "qvariant.h:42:21:", 17qvariant.h:42:21:) = 17 [pid 13530] write(2, " ", 1 ) = 1 [pid 13530] write(2, "calling fdopen: Bad file descrip"..., 35calling fdopen: Bad file descriptor) = 35
This is a dup of bug 13675. *** This bug has been marked as a duplicate of 13675 ***