3

I'm working on building Qt 4.8.1 in VisualStudio 2005 and I was getting an issue that the compiler could not find _fileno.

After some research, I found that in stdio.h it has

#ifdef  _POSIX_
_CRTIMP __checkReturn int __cdecl fileno(__in FILE * _File);
#else
_CRTIMP __checkReturn int __cdecl _fileno(__in FILE * _File);
#endif

I then looked through the qt code and found that qfsfilengine_win.cpp and qfilesystemengine_win.cpp both have

#define _POSIX_

It seems to me that this would be a mistake, and if I remove these lines, it seems to build successfully.

Does anyone know why these files would be defining _POSIX_?

Thanks.

Lol4t0
  • 12,444
  • 4
  • 29
  • 65
Liron
  • 2,012
  • 19
  • 39
  • 1
    It is not a mistake, posix names have been deprecated for a long time. These files don't *define* `_POSIX_`, they merely #if it. Looks like Qt took a short-cut to try to deal with the problem. Don't edit compiler header files, you'll dig yourself a really deep hole. – Hans Passant Apr 03 '12 at 20:08
  • 1
    qfsfilengine_win.cpp and qfilesystemengine_win.cpp both have #define _POSIX _ in them. stdio.h just #if's it, but my question is about the Qt cpp files which seem to have an incorrect #define. – Liron Apr 03 '12 at 21:04
  • 1
    Well, it is technically incorrect on Windows, but those are the kind of hacks that libraries use when they need to support multiple platforms and compilers. You are asking an XY question. You assume that Y is the problem but it isn't very likely that's the real problem. We have no idea what X looks like. If you want to use `fileno` in your code instead of `_fileno` then you are probably not using a QSomething class like you should. – Hans Passant Apr 03 '12 at 21:17
  • I want to use `_fileno`, and the Qt code defines QT_FILENO as `_fileno`. The problem is that in a different place in the Qt code, they are calling #define _POSIX_ which means that `_fileno` doesn't exist. Which then causes the build to fail. – Liron Apr 03 '12 at 21:29
  • Note, this failure is in building Qt, not in integrating Qt into my code. – Liron Apr 03 '12 at 21:31
  • We're getting a wee bit closer to X. Building Qt in Windows is known to work well, many programmers have done so. Some use the pre-built binaries. Exactly why you have this problem is still extremely muddy. – Hans Passant Apr 03 '12 at 21:48
  • I have built previous versions of Qt successfully myself. If I have time I'm going to try and do the same build for VS2010 and see if I have the same problem there. At least that would be a clue. – Liron Apr 03 '12 at 22:24
  • Oh man - so the first time I built Qt I forgot to include the sqlite plugin which we needed. I took a clean unzip of the plugin and configured with the additional config flag to add sqlite and then rebuilt without removing the `#define _POSIX_` calls in the above 2 files and it worked. – Liron Apr 03 '12 at 22:29
  • @LKIM: Haven't ever seen fileno used in windows code. Which means you're doing something weird. Like using wrong mkspec when configuring Qt. – SigTerm Apr 04 '12 at 00:46
  • Seems that the problem is that I had removed the precomile_headers flag from the qmake.conf CONFIG. – Liron Apr 04 '12 at 21:48
  • So qt_pch.h calls `#undef _POSIX_` which means that when compiling when using precompiled headers, you don't have this problem, because even if the above 2 files define `_POSIX_` it gets undefined by the pch. This seems to me that the `#define _POSIX_` in the above 2 files is a bug and incorrect. – Liron Apr 04 '12 at 22:01

1 Answers1

1

It seems that this is indeed a bug in Qt. If you are building Qt for windows without precompiled headers and you run into this problem, just delete the #define _POSIX_ calls in qfsfilengine_win.cpp and qfilesystemengine_win.cpp and it will build successfully.

Liron
  • 2,012
  • 19
  • 39