Question

Is it possible to include C/C++ header files in a qmake (.pro) file?

I have a version.h header file with several definitions for my project (strings, version numbers, etc.). I also have an .rc file for Windows to add version info to my exe/dll, which includes this header file.

So, can I somehow get the #defines in my header file to be processed in my .pro file, or what other way could I use to define strings and other constants in one file and have them accessible from my C++ code, the .rc file and the .pro file by including that file?

Was it helpful?

Solution

You can use the DEFINES variable in the .pro file. The following works with gcc and clang.

# A definition without a value
DEFINES += USE_X86_ASM

# A definition with a value
DEFINES += SOME_DEFINITION=value

# A more complicated value needs quoting
DEFINES += COMPANY_NAME=\"Weird Apps LLC.\"

# Defining a string can be tricky
DEFINES += STRING_VALUE=\"\\\"This is a string literal\\\"\"

# The value comes from the build environment.
DEFINES += COMPILED_BY=$(USER)

The definitions are passed to the C/C++ compiler. I don’t know if the rc compiler also gets them, though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top