Imagix 4D User Guide


Step 3b - Resolve Macro Definitions

Conditional compilation, using #ifdef style preprocessor directives in combination with macro definitions and undefines, enables the same base set of source code to be built into a family of executables. When this approach is taken, the macro definitions and undefines are typically generated by passing -D (define) and -U (undefine) options as part of the compiler command line. These options are specified in makefiles or IDEs.

When loading source code into a project, the Imagix 4D source analyzer does a full semantic analysis following the same #ifdef style directives. Therefore, it is important that the -D and -U flags normally passed to the compiler for conditional compilation also be specified in the Imagix 4D project settings.

If these aren't specified, a number of issues could ensue - ranging from simply including the wrong code into the project to omitting or incorrectly using important symbol definitions during the analysis. Issues of this latter type normally result in the source analysis generating warning and error messages.
Consider the following scenario. In the Analyzer Results window, you might see an analyzer warning about an unknown symbol.

Analyzing c:/dev/check.c
   c:/dev/check.c, 22: warning - avoiding unknown typename near symbol u_intlong

When you double-click on the warning line, an Imagix 4D File Editor opens to line 22 of check.c. There you find that u_intlong is used as the type of a function parameter.

Note that u_intlong is not colored in the file editor. That, together with the warning message, cause you to suspect that u_intlong is not defined. To check, you search for u_intlong in the Grep Search tab, and navigate to the definition that shows up.

This confirms your suspicion. The definition occurs in grey text (depending on your setting in the Tools > Options... > File Editors > Symbol Display dialog), indicating that the definition was omitted from the source analysis due to conditional compilation. In this case, the issue seems to be that there is no macro _CONDITIONAL_COMPILE_ defined.

After adding -D_CONDITIONAL_COMPILE_ in order to define the missing macro, you rerun the analysis, and find that the warning message goes away. The type is now colorized in the file editor where it is used as a parameter type.

And the definition of the type is also colorized, and is no longer displayed in grey text.

At this point, you become confident that a -D_CONDITIONAL_COMPILE_ option is required to more precisely analyze your code.
If problems of this type occur in generating your Imagix 4D project, the steps that you take to review and correct your project settings will vary, depending on the approach you're using for loading in your code.

Dialog Based Approach

With the Dialog Based Approach, the -D and -U options are all manually defined, in the PP Flags field of the Source Files tab of the Project > Data Sources dialog. If you are not already familiar with the -D and -U options used to compile the code, you can review the makefiles or the IDE settings used to build your software, and attempt to locate the -D and -U options that are specified there. Finding a list of the required options is much easier than individually identifying and resolving each specific option.

Once you have specified as many -D and -U options as you can by checking makelogs, IDEs and knowledgable collegues, you can follow the scenario above to identify additional options. You can incorporate your findings by manually add these -D and -U flags into the PP Flags field on the Source Files tab on the Project > Data Sources dialog.

Extract from Makelog

In the Extract from Makelog approach, macro definition settings are generated from -D and -U flags in the logfile, according to the makelog processing rules that you have set. If it appears that macro definitions are missing, first select the Extract from Makelog data source on the Project > Data Sources dialog. This will be the first data source listed on the left of the dialog. Review the settings you have made in the Processing Rules tab of the dialog.

If you're confident that those are correct, you can manually add any necessary -D and -U options. Switch to the Makelog tab, and enter the required -Dmacro or -Umacro into the Options entry field. Then click the Process Makelog button. The -D and -U options that you entered will be propogated to all of the individual Dialog Based (C/C++) data sources that are created.

Microsoft Visual Studio-Based

Under the Microsoft Visual Studio-Based approach, macro definition settings are generated automatically from Visual Studio's .sln and .vcproj project files.

First make sure that you have the Visual Studio settings and the Configuration correctly set on the Project or Solution tab of the Project > Data Sources dialog. If that doesn't resolve the macro definitions, add any required -D and -U options into the tab's Options entry field. These will supplement those extracted from the Visual Studio project files.