C/C++ with Clang using the Project Configurer#
The Project Configurer can create a project from C, C++ and/or Objective C source code. It provides a file directory browser user interface. The user selects the files that constitute the project. The interface also allows the user to specify compiler options. The user is expected to specify any include files that are not part of the project. he Project Configurer provides a quick way for users to get an understanding of their architecture. It is not suitable for complex projects where there are many different compiler options.
Creating a project#
Select New Project from the File menu
Select either Embedded or All on the Profiles page and click Next
Select C/C++ (Clang) in the Module Type dropdown
Set Datasources to Project Configurer
Use Add Directory to add directory trees of source files to the project
Use Add File to add a single file to the project
Use Add Unit to add another Unit to your project (more on this below)
Select files or units and click on the Options button below Add Directory (selected blue in below image). Use this dialog to add compile options (more on this below)
Configure options in the Options tab (at the top of the dialog, more on this below)
Press Create Project
Unit#
Units allow you to indicate the “link” units for your project. This can be important if the source code in the project builds multiple DLL’s or shared libraries. A Unit is a scope that allows Architect to resolve references to multiply defined symbols by choosing the definition in the same Unit.
Compile Options#
The Options button (in the lower half of the dialog, below Add Directory) can be used to set compiler options on a Unit (the above picture shows one Unit called httpd2055) or a file. These options are switches passed to the clang compiler.
-I adds to the include path. Example: -IC:\MyProject\include
-D defines a macro. Examples: -DWIN32, -DOS=WIN32
Compiler options can either be merged with the options from the enclosing Unit or Directory or can be a stand alone set of options that does not include options from the outer scope.
Project Options#
The Options tab (at the top of the dialog, between Datasources and Partition Options) can be used to set up a number of project options. Some helpful ones to use are:
Include standard Clang headers
Include this if you want to use the standard Clang headers. It is generally a good idea to enable this option if you haven’t specified the headers that are used by your compiler
Automatically detect include directories in source tree
Use this to force the generation of the include path based on the header files in your source tree. This is useful if the header files are present in the source tree but the include paths aren’t set up correctly. Please note that this option is now enabled by default in version 10.1.2+.
Include Directories
You can specify any additional include directories for the entire project.
Compiler Options
You can specify any additional compilation options for the entire project.
Avoiding Common Pitfalls#
Most issues using the Project Configurer relate to providing incomplete compile information.
To see the diagnostics, run the Clang report: Reports –> Clang Reports –> Diagnostics by File.
Missing Header Files#
If the header files are missing, the files may not parse correctly or may not parse at all. This is often because you don’t have the system include file. Please make sure that you have the header files from the development environment installed. Use Options in the Project Configuer to specify additional include files.
Undefined Macros#
While this is generally not always a big problem, lack of macro definitions can make the code unparsable. Specify macros through Options in Project Configurer.
Multiply Defined Symbols#
You can get multiply defined symbols if you include two files which are linked into different binaries and have the same symbols. In this Lattix will mark the multiply defined symbol as an external. To avoid this, create your project with a unit for each binary.
Check for Errors#
Check for errors by bringing up the Clang Reports using Reports->Clang Reports…->Diagnostics By File. The errors that cause analysis inaccuracies are typically from missing include files. Fix the errors and re-create (or update) the project. Note that you can specify additional include directories in the Options tab in the Create New Project dialog.
Hint: To minimize the time, remember that you can test by compiling just a single source file that is giving you errors. The Options tab on the Create New Project dialog has an section called Include files matching these names. Simple enter the full path name of the file and then only that file will be compiled.