Qt automatically generated .rc file cannot open include file 'windows.h' - c++

In my Qt 5.9.1 project, I wanted to add version info to the executable to help with debugging. So, I added VERSION = 1.0.0 to the 'Project.pro' file, which automatically generated a 'Project_resource.rc' file, as expected from Qt Version.
However, the project now fails to compile, giving the error RC1015: cannot open include file 'windows.h' on the line #include <windows.h> in 'Project_resource.rc'. I know that windows.h is known by the compiler at another point in the program, because in main.cpp I #include <windows.h> and use a function from there, and that successfully compiles. I just can't figure out why the 'Project_resource.rc' can't find that same file.
Note: I have the following above the VERSION = 1.0.0 line in 'Project.pro', which is how my main.cpp can find <windows.h>.
INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt"
LIBS += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt/x64"
INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/um"
LIBS += -L"C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/um/x64"
INCLUDEPATH += "C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/shared"

Remember .rc files have their own AdditionalIncludeDirectories.
It's possible that your project had set the Windows SDK properly set as one of the Include Directories values (hence your .cpp file resolves the windows.h header file) but not the .rc file (which would explain why windows.h can't be resolved from it).
If you're using Visual Studio 2019, try this:
Right click your .rc file on the Solution Explorer
Go to Resources -> General
Edit the Additional Include Directories
Include $(WindowsSDK_IncludePath) Macro
Be sure to accept and save the change.
You should stop seeing this error right after having done this.
If the ".rc file cannot open include file" was referring to a different file, just try the same but use the proper macro/path value on step 4.

Related

Qt include Class of another Project (Cannot open include file: 'foo.h')

I just started with Qt and some issues came up. I'm sure it must be a simple solution but I just can't find it.
I have two Projects, ProjectOne and ProjectTwo. I'd like you use the class foo from ProjectOne in main.cpp from ProjectTwo. When I run my Programm The Files are copied/referenced into ProjectTwo, but when i try to include foo in my main.cpp (#include "foo.h") i recieve the following error:
> main.cpp:3: error: C1083: Cannot open include file: 'foo.h':
> No such file or directory
Here's my Structure:
-ProjectOne
-ProjectOne.pro
-Headers
-foo.h
-Source
-foo.cpp
-Other files
-ProjectOne.pri
-ProjectTwo
-ProjectTwo.pro
-ProjectOne
-ProjectOne.pri
-Headers
-foo.h
-Sources
-foo.cpp
-Sources
main.cpp
Here's what i edited on my .pro and .pri files
**ProjectOne.pri**
INCLUDEPATH += $$PWD
SOURCES += $$PWD/foo.cpp
HEADERS += $$PWD/foo.h
**ProjectTwo.pro:**
include(../ProjectOne/ProjectOne.pri)
QT += core
SOURCES += foo.cpp
HEADERS += foo.h
I'm using Qt Creator 3.1.2 on Windows 7. My Programming Language is C++ and I'm compiling with VisualStudio 10 Express.
Any help is greatly appreciated!
When including a file that isn't directly in you project folder you need to include it with full or relative path.
i.e.
#include "bar/foo.h"
or
#include "../../bar/foo.h"

Qt Linking with Firmata

I am running on a Windows 7 with Qt SDK(C++), Firmata, and Arduino Softaware
I was wondering why the firmata.h is not working
#ifndef Firmata_Boards_h
#define Firmata_Boards_h
#include <inttypes.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h" // for digitalRead, digitalWrite, etc
#else
#include "WProgram.h"
#endif
the problem is when i try to compile using Qt it says
D:\SGU\Semester 8\Program\OpenCVMultithreaded\Boards.h:9: error: Arduino.h: No such file or directory
can we really use firmata on Qt? because in the internet I only found Arduino software using firmata, not on Qt itself.
I tried :
INCLUDEPATH += "D:\opencv\build\include"
INCLUDEPATH += "D:\opencv\build\include\opencv"
INCLUDEPATH += "C:\Program Files (x86)\Arduino"
INCLUDEPATH += "C:\Program Files (x86)\Arduino\hardware"
INCLUDEPATH += "C:\Program Files (x86)\Arduino\lib" I
INCLUDEPATH += "C:\Program Files (x86)\Arduino\libraries"
INCLUDEPATH += "C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\Arduino.h"
But it doesnt work.
This is not a linking issue but a compilation issue, and has nothing to do with the specific library you are using. You probably haven't specified where to find the header files nor the library files.
In your project file (.pro) add
INCLUDEPATH += PATH_TO_ARDUINNO_HEADERS
for example PATH_TO_ARDUINNO_HEADERS can be C:/Arduino/include.
To specify libraries you need to use the LIBS variables, for example
LIBS += "-Lc:/Arduino/lib" -larduinnoshared
See the qmake reference for a complete guide on including\linking to external items
Edit:
The include path is what is going to be prefixed to find "Arduino.h".
So if the file is at
"C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\Arduino.h"
you need to use
INCLUDEPATH += "C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino"
All the other paths you posted are invalid for this file. You put only directories containing header files in the includepath.

Qt5: Poppler weird linker error

I downloaded pre-built win32 poppler binaries from this page. Added the path for the include folder and lib folder in the .pro file:
INCLUDEPATH += "C:\\test_folder\\poppler-0.24.5-win32\\include\\poppler-qt5"
LIBS += -L/"C:\\test_folder\\poppler-0.24.5-win32\\lib"
In main.cpp i include "poppler-qt5.h" without errors, so I would think that poppler was added correctly. However when testing it by opening a pdf file, as described here,
QString path = "C:\\Windows\\System32\\spool\\PRINTERS\\test_file.pdf";
Poppler::Document *doc = Poppler::Document::load(path);
I receive a linker error:
Can someone help me out here?
I am missing the -l in yout LIBS line
LIBS += -L/"C:\\test_folder\\poppler-0.24.5-win32\\lib" -lpoppler-qt5
Eventually rename the lib since .dll.a is not a standard extension in windows.
Edit: Works without renaming the library:
.pro File:
INCLUDEPATH += $$quote(D:\Users\username\Downloads\poppler-0.24.5-win32\poppler-0.24.5-win32\include\poppler-qt5)
LIBS += -L$$quote(D:\Users\username\Downloads\poppler-0.24.5-win32\poppler-0.24.5-win32\lib) -lpoppler-qt5
.cpp File:
#include <QApplication>
#include <mycpp.h>
#include <poppler-qt5.h>
/* Some Code here */
QString path = "D:\\SomePDF.pdf";
Poppler::Document *doc = Poppler::Document::load(path);
/* More Code here */
I had the same problem and I resolved it with this method:
Copy dll file if you find in folder \poppler-0.24.5-win32\bin\ to folder where Qt generate executable file. Then download zlib1.dll and insert this dll to folder where Qt generate executable file. Try now.
This works for me. I compiled with qt 5.3 in Windows XP SP3.

QT - Includepath with an "include" as a directory wont include

I'm trying to add the header file afxwin.h to my QT project. The include path I added to my project file is below.
INCLUDEPATH += C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include
This is not behaving correctly, as it does not include the headers I'm looking for.
It highlights the "include" portion of the path in Red and when hovering over it displays;
include(filename)
[Conditional]
Includes the contents of the file specified by filename into the current project at the point where it is included. This function succeeds if filename is included; otherwise it fails. The included file is processed immediately
Is there a way to escape the include ? I have tried double quotes and it appears to have no effect. Any Ideas ?
Usually double qutoes should work, but if they don't work for what reason ever you can always try using the old 8.3 format:
INCLUDEPATH += C:\PROGRA~1\MICROS~1.0\VC\atlmfc\include
Keep in mind it isn't necessarily ~1 all the time, it could as well be ~2, ~3 etc.
You can use dir /x /p on C: and C:\Program Files (x86) in order to find out the short names for "Program Files (x86)" and "Microsoft Visual Studio 10.0".

How to use precompiled headers in Qt project

My IDE: Visual Studio 2010, I use Qt add-in for VS, Qt ver. 4.8.1
I have faced with the problem while trying to create precompiled header(pch) in my Qt project.
My usuall approach for creating pch in non Qt project is:
Create header;
Include files which will be precompiled in header;
For every source file in the project state in it`s properties if it will use pch;
For one source file in project state creation of pch;
Include pch in all source files.
As those action failed for Qt project I decided what it happens due to pch should be included to all files generated by MOC.
I read the article in QtAssistant on precompiled headers and did the following:
Created header file;
For all .cpp files in project set option use pch and for one create
Converted to qmake generated project
I ran qmake -project
I modified generated .pro file, here it is:
TEMPLATE = app
TARGET =
DEPENDPATH += . GeneratedFiles
INCLUDEPATH += .
PRECOMPILED_HEADER = StdAfx.h
QT += network
Input
HEADERS += server.h StdAfx.h
FORMS += server.ui
SOURCES += main.cpp server.cpp StdAfx.h.cpp
RESOURCES += server.qrc
I ran qmake
open .pro file and tried to build it and got the error:
Error 2 error C1083: Cannot open include file: 'StdAfx.h': No such file or directory
What I am doing wrong?
Create your precompiled header file and include the desired headers.
pch.hpp:
// precompiled headers
// add C includes here
#ifdef __cplusplus
// add C++ includes here
#include <iostream>
#include <QtGui>
#endif // __cplusplus
Then in your .pro file:
CONFIG += precompile_header
PRECOMPILED_HEADER = pch.hpp
HEADERS += pch.hpp
Qmake will now automatically set the correct options for the compiler.
I found solution.
The only thing needed to be done in order to use precompiled header in project is to include
the following statements in .pro file:
CONFIG += nameOfPrecompiledHeader.h
PRECOMPILED_HEADER = nameOfPrecompiledHeader.h
win32-msvc* {
PRECOMPILED_SOURCE = nameOfFileInWhichCreateOptionWillBeSet.cpp /* other .cpp files will be with use option*/
}
after .pro modification and running qmake all .cpp files will be set up for usage of pch and one for it`s creation(nameOfFileInWhichCreateOptionWillBeSet) and .pch will be generated