开发者

Possible to include C/C++ header files in a .pro file?

开发者 https://www.devze.com 2023-01-10 09:33 出处:网络
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 f

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消