QT c++ “Windows.h no such a file or dictionary in main.ccp”

问题内容:

My Qt c++ cross platform game work with windows but when it comes to the Linux there is an error “Windows.h no such a file or dictionary in main.ccp“.

问题评论:

5  
Windows.h is, unsurprisingly, a Windows-only header file. It doesn’t exist on Linux. You’ll need to find a Linux-compatible way of doing whatever you’re trying to do (or seeing as you’re already using QT, a cross-platform way).
    
no such a file or dictionary are you sure it isn’t no such file or directory?
3  
Since you’re using Qt, why are you including Windows.h to begin with? Is there something from that header that you actually need?
2  
“Windows.h” “cross platform” pick zero or one of the above.

答案:

答案1:

How would you expect windows.h to exist on a nom-Windows OS? On Linux you’re supposed to have qt.h or so (and change those library function calls to Qt ones, instead of WinAPI).

windows.h is available only on Windows XP or newer (and Windows 2000 Professional). You can only choose one option: cross-platform or Windows.

I also doubt your program is right, since main.ccp is not a valid name for a C++ source file.

答案评论:

答案2:

You only need windows.h on Windows-Platforms. So my best advice for you is to use this:

#ifdef WIN32
#include "windows.h"
#endif

This will include windows.h only if you are on Windows.

答案评论:

    
Then how would the program compile if one of the lines reads CreateWindowEx(blah blah)?
    
This is a Windows Function. Therefore you cannot use it. For OpenGL, the easiest way to do it is by using GLUT or SDL.
    
That would require extra job for an already-written code.
    
Qt does it for you. Please give us your main.cpp

原文地址:

https://stackoverflow.com/questions/47754902/qt-c-windows-h-no-such-a-file-or-dictionary-in-main-ccp

Tags:,

Add a Comment