How to add pre processing defs (macros) to qt creator?

后端 未结 6 1024
面向向阳花
面向向阳花 2020-12-14 00:42

In Eclipse there is an option to specify pre processing defines (#ifdef macros) to a project by using the Symbols option in Paths and Symbols. This helps in effective indexi

6条回答
  •  自闭症患者
    2020-12-14 01:22

    I think the initial answers are good, but they require that you manage your configuration manually whereas there're ways to let the IDE manage this for you automatically based on whether you have a release or debug configuration selected.

    This bit may be redundant, but please note that this will work for you only if you are using the IDE for building. Obviously, if this is not the case, you will need a different solution.

    Steps

    Since pictures are worth a thousand words, here's an example of how you define a debug macro for your debug build using Qt Creator 4.3.1:

    1. Make sure you have your Debug configuration selected;

    1. Go to the Projects section on the left menu;
    2. Go to the Build section

    1. Under Build Steps, look for the Additional arguments input box;
    2. Enter your macro definitions (e.g. DEBUG for your #ifdef DEBUGs in the code; in my case it's __CTS_DEBUG__)

    The macro will now only be defined when you're using your debug config; when you choose your Release config (see step 1), it will become undefined automatically and your conditionally-compiled debug code will be removed, as shown in the pictures below, which is just what you always wanted.

    Results

    With the debug config selected

    With the release config selected:

提交回复
热议问题