When attempting to generate C++ stubs, especially safe stubs, C++test attempts to compile user hea
Check to make sure the user has not redefined assert.h. In the cases that triggered this article the user had their own version of assert.h and the safe stubs build included that file rather than the standard C library file. The user version contained C++ code that the C compiler could not build causing a compiler fail. The name of the user file was capitalized (Assert.h) but the user was building and testing the project under Cygwin on Windows, which preserves the case but is case insensitive. The Assert.h file directory was specified with a –I option in the compile. This options searches the specified directory before the system directories.
To resolve the issue the user file can be renamed which also requires renaming in all source code. If this is not feasible, and the user file is required, try the following fix.
1.For GCC remove the –I option that specifies the directory that the user file is in and replace it with the –iquote option.
* -I /usr/myproj/myinclude // remove
* -iquote /usr/myproj/myinclude // use instead.
2.In the user’s project code replace references to <Assert.h> with “Assert.h”. Any other includes for files in the same directory will also have to change from angle brackets to double quotes.
The user’s project will find the user version of the file in the directory specified by the "–iquote" option while Parasoft will use the standard C library assert.h file (since parasoft uses <assert.h>). This will eliminate the inclusion of the user file in stubs generation.
For Microsoft Visual C++ check the properties in Tools > Options > Projects and Solutions > VC++ Directories for Visual C++ BEFORE version 2010. For 2010 and later check the include directories in the project properties.
Note that changing the case of the file name to mixed, upper or capitalized names may not distinguish them. In windows assert.h and Assert.h are the same file name (try and create two such files in the same directory, Windows won’t let you). This is due to Windows keeping backwards compatibility with older file systems that are case insensitive. Windows and the NTFS preserves the case on file names but will treat them as the same otherwise.
The same may be true of other Operating Systems. For example Linux may preserve the case but be case insensitive for any files located on an NTFS file systems (such as those shared with Windows). Other Operating Systems should be checked as well.
In general it’s possible but a bad idea to name user headers with the same name as standard C headers. Remember that Parasoft stubs requires the standard C library assert.h file and uses the same compiler options as the project. If a conflicting header is found you can expect the stubs generation to fail.